I am trying to send a with attachment where the attachment file could be any type of file(like txt,image,pdf etc) from a sd card.
I used these
String filelocation="file:/"+attachment_file_path1.getText().toString();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent.setType("text/plain");
String to[] = {"destination#yahoo.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "bodyyyyyyyyy");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filelocation));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "my mail");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
N:B: if i print the attachment_file_path1.getText().toString() it shows like "/storage/sdcard0/myfolder/my.txt"
my email is sent to the destination but my attachment is not sent.
How can i solve the problem??
Change your emailIntent.setType(text/plain) to emailIntent.setType("*/*") for allowing to send any file type.
Path format is :
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra / as this points to the root directory, i.e.:
file:// + /sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
Related
I would like to attach string as html attachment in android mail,how can I achieve this.Kindly help me with a snippet to do this.Thanks a lot.
Use intent to send email like below way .. and if u want to add some string as attachment u have to save that content into some directory with .html ext and later u can add it as attachment into email intent. [This code for idea it may need few modification as per ur app requirement..]
String emailText = "email message";
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demo#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
String attachContent = "<html> content </html>";
/* this method u have to write, to save the string into html file
into cache or any other dir */
saveFile(getCacheDir()+"/attach.html", attachContent );
File file = new File(root, getCacheWebDir()+"/attach.html");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
I know this question is already ask in the stack overflow, and I looked around them but don't get any clue. Actually I have written code for sending an image file as an attachment to my mail and its working fine. The code I used for sending an image file as an attachment is shown below. Can anyone tell me what are the changes I need to do to send the image file in the body of mail? Any clue will be helpful.
Code for sending the image as an attached file
Uri imageUri = Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" + fileNameArray.get(position));
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/png");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(i, "Send email"));
only work in device not in android emulator..
http://blogingtutorials.blogspot.com/2010/12/send-email-with-attached-file-in.html
Try using the following intent:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:/"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
I am sending a pdf file in email attachment, attachment is going successfully in email and it is showing me in email as attachment, but when i download this pdf it having no content i.e. it's size is zero byte.
Am I missing some permission? or Any solution regarding this?
Here is my code
private void emailSend(String emailString, String subject, String pdfPath){
String[] email = { emailString };
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"MY body");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
Finally i got the solution to my problem from this post.
I use
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(pdfPath)));
instead of
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
it resolved my issue.
Thanks
I've done this for sending any file from SD card with mail attachment...
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));
i want to send a .doc file as an attachment via email.
i am using the code below:
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
"Song Pad.");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Please see the attached document.");
final File file = new File(dirPath + "/" + filename
+ ".doc");
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + file.getAbsolutePath()));
MainActivity.this.startActivity(Intent.createChooser(
emailIntent, "Send Email..."));
the attachment goes successfully to email but when i open it on device it shows message
Unable to find viewer for plain/text.
on the other hand when i send doc file not via my app then it opens perfectly.
please guide . i think there is little mistake..
thanks..
You should use a mime type of .doc documents application/msword.
Try:
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(file);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("c:/logo.png"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"sivafarshore#yahoo.com");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
startActivity(Intent.createChooser(emailIntent, "Email:"));
I am using this kind of coding for attach image file,this code sent attach with email,but that attach file dose not contain no image,what can i do for display attach image file.
Hey... it seems you are trying to attach something that is inside your C: drive. That's not possible :) You can only attach images on the sdcard folder of the handset. For instance:
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("file:///sdcard/logo.png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"sivafarshore#yahoo.com");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
startActivity(Intent.createChooser(emailIntent, "Email:"));
To know where the sdcard folder is mounted, you use the Environment.getExternalStorageDirectory() method.