0

I am creating utility to send email. In my code i use chooser intent to choose email app to send email. It work perfectly but the problem is that if i use attachment file in this code using Uri then in chooser i choose G-mail, and then G-mail is stopped. If i send email without attachment it work good. Can any one solve my problem. Here is my code.

public void SendEmail() {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setData(Uri.parse("mailto: "));
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL,to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, body);
//        intent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(intent, "Send Mail..."));
}    

In this code a line is in comment. if i use this line then G-mail is stopped. I am using this line for file attachment. Help me please.

2 Answers2

1
/**Use the below Code Snippet**/

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email");
String to[] = {""};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + "Your URI"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
yash786
  • 1,151
  • 8
  • 18
0

Use this code it's works for me correctly:

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                String aEmailList[] = {"info@marutinandan.com"};
                //String aEmailCCList[] = { "user3@fakehost.com","user4@fakehost.com"};
                //String aEmailBCCList[] = { "user5@fakehost.com" };

                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
                // emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
                // emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);

                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "your subject");

                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "your message body.");

                startActivity(emailIntent);
Deep Doshi
  • 77
  • 6