6

When I try to send an email Intent no matter if I am using INTENT.ACTION_SEND or ACTION.SENDTO and use the stock Sony Xperia Active email client the subject and the recipients show up fine but the body is empty except for the standard comment pasted by the client. On my Samsung Galaxy Note 2 the same code works like charm.

    if(mPrefs.getBoolean("alternative_email_client", false)){
        Intent send = new Intent(Intent.ACTION_SENDTO);
        String uriText = "mailto:" + Uri.encode(emailStrings[6]) + 
               "?subject=" + Uri.encode("The subject") + 
               "&body=" + Uri.encode(emailBody);
        Uri uri = Uri.parse(uriText);
        send.setData(uri);
        startActivity(Intent.createChooser(send, "Email verschicken"));
    } else {
        Intent send = new Intent(Intent.ACTION_SEND);
        send.putExtra(Intent.EXTRA_EMAIL, emailStrings[6]);
        send.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
        send.putExtra(Intent.EXTRA_TEXT, emailBody);
        startActivity(Intent.createChooser(send, "Email verschicken"));
    }
neominik
  • 63
  • 1
  • 5

4 Answers4

11

To send an email with a body, use message/rfc822.

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "to1@example.com", "to2@example.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject of the email");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Content of the email");
startActivity(sendIntent);

Hope this helps.

Aswin Rajendiran
  • 3,399
  • 1
  • 21
  • 18
  • Okay this helps with the body, but using this I get a new problem: the recipients are gone. How to fix that? – neominik May 15 '13 at 10:39
  • Weird. I tried this with Gmail and I do see the recipients. What app are you trying to send the email from? – Aswin Rajendiran May 16 '13 at 00:22
  • This works for me too: I've forgotten to use a String-Array for the EXTRA_EMAIL. It doesn't work with a single String. – neominik May 21 '13 at 10:40
  • For people viewing this nowadays. For `API >= 15` this may not work. So try: https://stackoverflow.com/questions/4883199/using-android-intent-action-send-for-sending-email – JFreeman Jul 10 '21 at 05:09
3

I use body properties for gmail and EXTRA_TEXT for other email. I've tested for different email app such as samsung email, oneplus email, and LG email, they seems to support EXTRA_TEXT but gmail is supporting "body" properties.

 fun composeEmailMessage(context: Context,  subject: String, body: String, emails: Array<String> = arrayOf()) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, emails)
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
intent.putExtra(Intent.EXTRA_TEXT, body)//other emails app
intent.putExtra("body", body)//gmail
if (intent.resolveActivity(context.packageManager) != null) {
    context.startActivity(Intent.createChooser(intent, "Send email via..."))
}

}

0

Try to add the type of message

...
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, myMessage);
...
j.holetzeck
  • 4,048
  • 2
  • 21
  • 29
  • Well I really thought I'd have that. But even if I'm adding that line the body doesn't show in the stock email app. – neominik May 15 '13 at 10:37
0

First create a selector. Important, that after "mailto:" leave it empty.

val selectorIntent = Intent(Intent.ACTION_SENDTO).apply {
    data = Uri.parse("mailto:")
}

Then the email intent itself:

val emailIntent = Intent(Intent.ACTION_SEND).apply {
    putExtra(Intent.EXTRA_EMAIL, arrayOf("email@email.com"))
    putExtra(Intent.EXTRA_SUBJECT, "This is a subject")
    putExtra(Intent.EXTRA_TEXT, "Body text")

    selector = selectorIntent
}

And open the email app:

if (intent.resolveActivity(packageManager) != null) {
    startActivity(intent)
}

(The solution is in kotlin)

Marci
  • 899
  • 10
  • 13