3
I am trying to send a personalized email through new Intent(Intent.ACTION_SEND), containing in the email body a formatted HTML, but when selecting the Gmail application, for example, the whole style html is ignored. What I’m trying to do is the following:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<h1>Sou um H1</h1><p>Eu sou um paragrafo</p><p style=\"color:red;background-color:black;\">Eu sou um paragrafo colorido!</p>"));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
The email application is called correctly, but the part of the style of HTML is lost. It is possible to keep HTML intact in this way to send email through Intent.ACTION_SEND?
Did that work for you? Because I tested it here and it didn’t work! If only the
Intent.EXTRA_HTML_TEXTas you suggested, give the following alert on the console:Key android.intent.extra.HTML_TEXT expected String but value was a android.text.SpannableStringBuilder. The default value <null> was returned. and nothing appears in the body of the email. IfIntent.EXTRA_TEXTit appears only the contents ofIntent.EXTRA_TEXTin the body of the e-mail and not theIntent.EXTRA_HTML_TEXT. I’m testing on Android 5.0, and selecting the email manager of Gmail.– Fernando Leal
Sorry, there are two ways. I will change the possibilities, if it doesn’t work with you, I remove the answer.
– Jader Alcantara