4

I am using following code to send email from my Android app:

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"email@yahoo.com"});          
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("plain/text");
startActivity(Intent.createChooser(email, "Choose an Email App:"));

This works fine for all email sending apps, but it shows too many options like Facebook, Twitter, Bluetooth to send this email. I just wanted to see email apps to choose from.

So, I replaced email.setType("plain/text"); with email.setType("message/rfc822");

Now it shows only email apps and works fine for all email apps installed in my device except the outlook app. The outlook app doesn't send attachments properly. At the receiving end, I get strange characters instead of an attached file.

Then, I replaced email.setType("message/rfc822"); with email.setType("application/octet-stream");

This solved the outlook attachment issue, but now I am unable to send emails with the default android email app. It sends emails without attachments.

Syed Rafaqat Hussain
  • 1,009
  • 1
  • 9
  • 33
Adnan
  • 2,986
  • 7
  • 43
  • 63
  • did you checked this http://stackoverflow.com/questions/8280166/intent-with-settypemessage-rfc822-for-android-api-level-before-2-3-3 – Rahul Mar 02 '16 at 04:14
  • Yes, I have tried that way of sending emails. This ignores attachment. – Adnan Mar 02 '16 at 04:45

2 Answers2

2

Use this code to attach a file and send through email

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "text");
Uri uri = Uri.parse("file://" + myFile.getAbsolutePath());
email.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("message/rfc822");
startActivity(email);
Bharat Hangarge
  • 571
  • 5
  • 13
  • But its EXACTLY what I am looking for. Given the subject I was expecting to find this problem. However, when I tried it I got 'couldn't attach file' which means its on the right track BUT I probably have my file paths wrong. I have no SD card and cant assume one and the file is being generated by my app. I am writing it but I am not finding it by the looks. – Brian Reinhold Feb 10 '18 at 15:38
0

Use Intent.ACTION_SENDTO instead of Intent.ACTION_SEND.

Francesc
  • 25,014
  • 10
  • 66
  • 84