I have to following problem:
I want to send an email with an image attached to it.
I wrote this code:
File file = context.getDir("Files", context.MODE_WORLD_WRITEABLE);
File image = new File(file, "image.jpg");
Uri U = Uri.fromFile(image);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, U);
context.startActivity(Intent.createChooser(i, "Email:"));
The email is sent but there is no attachment.
Does anybody have any idea why the email is sent without the attachment?
EDIT
I have found the answer to my question. Because the image was stored on the internal storage, it did not have enough rights so it could not be sent via email. I've moved my image to externalStorage and now it's working :)
Thanks,
Ark
String smsBody = "Body of the Content";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject of the Mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, smsBody);
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile("mnt/sdCard/SampleImageFloder/TestImage.png"));
emailIntent.setType("vnd.android.cursor.dir/email");
activity.startActivity(Intent.createChooser(emailIntent,"Email:"));
Try this one -
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);
Just see my Existing Answer also
Related
So from my Android app I can send emails with attachment on Gmail. On outlook looks like it is attaching the file (.txt), but when I open the mail there is no attached file.
This is my code:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Uri uriFileToShare = Uri.fromFile(file);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, file.getName());
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uriFileToShare);
this.startActivityForResult(Intent.createChooser(emailIntent, activity.getString(R.string.send)+" "+file.getName()+" "+activity.getString(R.string.by_email)),code);
I have tried different solutions but no result.
The file of course exists and is not empty. As I said, on Gmail is correctly attached.
Any idea?
This code worked for me on outlook file attachment.
public static void emailLog(Context context) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
String filePath = fileDir + "/" + fileName;
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
File recordingFile = new File(filePath);
Uri fileUri = Uri.fromFile(recordingFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
context.startActivity(Intent.createChooser(emailIntent, "Some text..."));
}
I am developing an application in which i have to send an image via email, I tried with
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "xyz#gmal.com");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "message");
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.a));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
but its giving me as gmail has stopped unfortunately.How can I send an image via email,
Thanks in advance.
Get the image storage path by using the file,
File img = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/", imagename+".png");
Convert that file path in to Uri
Uri imageuri = Uri.fromFile(img);
Send the image via email using
Intent send_img = new Intent(Intent.ACTION_SEND);
send_img.putExtra(Intent.EXTRA_EMAIL, "xyz#gmal.com");
send_img.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
send_img.putExtra(Intent.EXTRA_STREAM, imageuri);
send_img.putExtra(Intent.EXTRA_TEXT, "message");
send_img.setType("text/plain");
send_img.setType("image/png");
startActivity(Intent.createChooser(send_img, "Send Email..."));
I can get both Mail and Gmail to attach multiple csv files to an email.
When sent via Mail all the attachments are delivered.
When sent by Gmail none of the attachments are delivered.
I have read the documentation Send Binary Content. I have searched but only found a solution for Gmail that does not work with Mail. Mail seems happy with just about any approach. Gmail just doesn't want to play.
Has anyone found a solution for sending multiple attachments that works with both Mail and Gmail?
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
String subject = context.getString(R.string.export_data_email_header);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.setType("text/csv");
ArrayList<Uri> uris = new ArrayList<Uri>();
if (diariesSelected) uris.add(Uri.fromFile(context.getFileStreamPath("diaries.csv")));
...
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);
And the code used to create the file
FileOutputStream fos = context.openFileOutput(path, Context.MODE_WORLD_READABLE);
OutputStreamWriter writer = new OutputStreamWriter(fos);
writer.append(builder.toString());
writer.close();
fos.close();
The following code is a snippet from one of my apps. As far as I remember, it works with GMail and Mail (Can't verify it at the moment.). It looks basically like your solution, but with a few little differences. Maybe one of them is what you are looking for. :)
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "address#mail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "The subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "The actual message");
ArrayList<Uri> attachmentUris = new ArrayList<Uri>();
for (File attachment : attachments) {
attachmentUris.add(Uri.fromFile(attachment));
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris);
startActivity(emailIntent);
Here you can get detail information https://stackoverflow.com/a/18225100/942224
by using below code i am attaching image file in gmail or Mail.... hope it will help you
Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
ei.setType("plain/text");
ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
ei.putExtra(Intent.EXTRA_SUBJECT, "That one works");
ArrayList<String> fileList = new ArrayList<String>();
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0;i<fileList.size();i++)
{
File fileIn = new File(fileList.get(i));
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345);
Hi i am developing an android application with email functionality. Here i need to send a CSV file from my path data/data/mypackage/files folder. I am storing the csv file there.It is saving there good.My csv file size is just 245 bytes only. But when i tried to send that file throught mail functionality of android is displaying "File too Large to attach.." message is displaying.
Here is my code:
String filelocation="file:///data/data/my package/files/excerDB.zip";
final Intent emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"purpletalk.raghu#gmail.com"});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "Attendence Report");
emailIntent .putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(filelocation));
startActivity( emailIntent);
But it is not working for me. Please advice me how can i send my file as a attachment to mail in my application.
i hope this code will help u
String FILE = Environment.getExternalStorageDirectory() + File.separator
+ "Foldername";
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// sendIntent.setType("text/html");
sendIntent.setType("application/csv");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
String temp_path = FILE + "/" + "Filename.csv";
File F = new File(temp_path);
Uri U = Uri.fromFile(F);
sendIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(sendIntent, "Send Mail"));
Enjoy this code!
I am sending mail through my application.
For that I am using following code.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
It just work fine but i want to attach an xml file with it.
Is it possible? How?
There are lots of similar questions asked with perfect solution in Stack Overflow already.
You can have look to few : here and here and here
Solution is to use with email intent : one more putExtra with Key-Extra_Stream and Value-uri to file.
And please go through the FAQ to undersatand How to better benifit from the site.
String pathname= Environment.getExternalStorageDirectory().getAbsolutePath();
String filename="/MyFiles/mysdfile.txt";
File file=new File(pathname, filename);
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, "Title");
i.putExtra(Intent.EXTRA_TEXT, "Content");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
i.setType("text/plain");
startActivity(Intent.createChooser(i, "Your email id"));
ACTION_SEND_MULTIPLE should be the action and then emailIntent.setType("text/plain"); followed by:
ArrayList<Uri> uris = new ArrayList<Uri>();
String[] filePaths = new String[] {"sdcard/sample.png", "sdcard/sample.png"};
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
For sending an attachment with gmail:
File should be on External storage device or created in External storage device
For that you need to add the following to Android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
get External path by
String pathname= Environment.getExternalStorageDirectory().getAbsolutePath();
Create a new file by
File myfile=new File(pathname,filename);
Write to file based on whatever logic you are applying
Now the Intent
Intent email=new Intent(android.content.Intent.ACTION_SEND);
email.setType("plain/text");
Put Extras
email.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(myfile)); email.putExtra(Intent.EXTRA_SUBJECT, "my email subject");
email.putExtra(Intent.EXTRA_TEXT, "my email text");
Start Activity
startActivity(Intent.createChooser(email, "E-mail"));