Reputation: 9872
It seems that Gmail 4.2.1 may have broken HTML-formatted emails. The following code worked perfectly prior to 4.2.1. The email that was sent from Gmail had the desired embedded links, bolded and underlined words. Unfortunately, after updating to 4.2.1, the email that gets sent appears as if all the HTML formatting has been stripped out. I am hoping there may be a workaround for this that maybe someone has found?
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
String[] toArr = new String[] { "[email protected]" };
intent.putExtra(Intent.EXTRA_EMAIL, toArr);
intent.putExtra(Intent.EXTRA_SUBJECT, "This is a subject");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("Hello, here is some <b>bold text</b> some <u>underline text</u> and <a href=\"http://www.google.com\">a link</a>."));
The interesting thing (or maybe not?) is that the compose preview of this email message shows all of the bolded, underlined and linked text as one would expect it to appear. But when it gets sent, the recipient gets the email with all of that stuff stripped out.
And yes, I am aware of this other question about this that was closed. I think that maybe it was closed prematurely and am hoping that the additional detail here may warrant another look.
MORE INFORMATION: Upon further research, this problem is way bigger than just sending HTML email via intents. If one creates a draft email using the GMail web app that has some formatting (bold, underline, hyperlinks, etc.), then open that draft email on your GMail Android app (v4.2.1) it will appear that all of your formatting has been kept. However, if you then send that draft email using your GMail Android app, all of your formatting will be stripped out before the email is sent.
Upvotes: 24
Views: 6951
Reputation: 9872
This was almost certainly a bug in GMail 4.2.1.
As of March 19, 2013, GMail 4.3 was released which appears to fix the bug.
Upvotes: 3
Reputation: 236
private void sendMail(String appName, String playStoreLink) {
String msg = "<HTML><BODY>Hello,<br>Recently,I downloaded <b><font color=\"red\">"+appName+"</font></b>"+
" from Play Store.I found this very challenging and a great game."+
"<br>I would like to suggest you this game.<br><br><a href="+playStoreLink+">Download</a><br><br>"+
"<br>Thank You</BODY></HTML>";
String sub = "Get it now. It is there in Play Store";
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("text/html");
email.putExtra(Intent.EXTRA_SUBJECT, sub);
email.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg));
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
Upvotes: 0
Reputation: 404
I'm sorry that you ran into this too Scott. I filed a bug report with Google in December but that just seems to be a black hole.
My need was to embed hyperlinks. My best work-around has been to send a text/plain or message/rfc822 email with the URL in plain text in the message. Oddly Gmail recognizes this and attempts to enclose it in < a > < /a > tags. Using this method I can get the link sent and clickable by the recipient but it looks like crap.
It's also a bit of a challenge to get the URL formatted such that Gmail recognizes the entire text of the link and properly encloses it.
Upvotes: 1