Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email body doesn't show when using an Intent

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"));
    }
like image 927
neominik Avatar asked May 11 '13 18:05

neominik


2 Answers

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[] { "[email protected]", "[email protected]" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject of the email");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Content of the email");
startActivity(sendIntent);

Hope this helps.

like image 50
Aswin Rajendiran Avatar answered Oct 16 '22 17:10

Aswin Rajendiran


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..."))
}

}

like image 26
Blissfulness Avatar answered Oct 16 '22 15:10

Blissfulness