Send HTML email with formatting in Android (style inline)

3

I'm trying to send a custom email through new Intent(Intent.ACTION_SEND) , containing in the email body a formatted HTML, but when selecting the Gmail application, for example, all style of html is ignored. What I'm trying 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 style part of the HTML is lost. Is it possible to keep HTML intact in this way of sending email through Intent.ACTION_SEND ?

    
asked by anonymous 25.08.2015 / 15:24

1 answer

1

Just use the Intent.EXTRA_HTML_TEXT parameter

i.sendIntent.setType(“text/html”);

i.putExtra(Intent.EXTRA_HTML_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>").toString());

OR

i.putExtra(Intent.EXTRA_HTML_TEXT, "<h1>Sou um H1</h1><p>Eu sou um paragrafo</p><p style=\"color:red;background-color:black;\">Eu sou um paragrafo colorido!</p>");
    
28.08.2015 / 13:07