It’s very easy to send email via an Android intent. Here’s an example where we already have the subject and body prepared but want to let the user decide on the recipient:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Email:"));
(It’s important to note that this should be attempted on a real device.)
I ran into some trouble with sending HTML in an email because it was being interpreted as plain text both in the user’s email client and in the recipient’s. Simply changing the MIME type didn’t help, but I eventually came across the solution:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(emailIntent, "Email:"));
Note that both the MIME type is changed and the EXTRA_TEXT is now set as Html.fromHtml(body) instead of just being passed a string with HTML in it. So far I’ve only tested this on a Nexus One running Android 2.1, but I’ll give it a try on some other platforms and see if it works.

Nice tip. Do you think there’s a way to see if message was sent? I tried to use startActivityForResult, but onActivityResult never got called.
| May 19th, 2010 @ 10:47 am
I would have guessed startActivityForResult also, but if that doesn’t work, I’m not sure what else to try. Sorry!
| May 19th, 2010 @ 11:38 am
I have just try your second code to send html message and i have a little problem.
When I chose the gmail app to send the email, all the html code is put in the body of the message in plain text.
Do you have this problem too ?
(my variabel ‘body’ is a string with HTML in it)
| June 1st, 2010 @ 4:32 am
It’s working !
I was doing a TextUtils.htmlEncode(body) befaure calling Html.fromHtml.
Just remove the htmlEncode and it’s solve the problem.
Thank you very much.
| June 1st, 2010 @ 4:58 am
Hi,
I tried your second code to send html message and its working fine for gmail but its not working for HTC email.where in nothing gets displayed in body of the mail.I tried it in HTC Hero.
| June 18th, 2010 @ 2:01 am
Hi Jum… Can you please give a sample code/example of body with textutil and html.fromhtml that works for you? Thanks in advance.
| July 21st, 2010 @ 2:45 pm
Actually my working code is exactly the seconde exemple of Ian.
I don’t use TextUtils, it was a mistake.
Here is a working code :
StringBuilder sb = new StringBuilder();
sb.append(“”)
.append(“”)
.append(“”)
.append(“”)
.append(“”)
.append(“”)
.append(“Test”);
.append(“”);
body = sb.toString();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType(“text/html”);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, “subject”);
startActivity(Intent.createChooser(sendIntent,”Email:”));
| July 21st, 2010 @ 3:02 pm
My html code has been removed from my previous comment.
Just make sure that the variable ‘body’ is a string with html in it.
July 21st, 2010 @ 3:05 pm
Thanks for the quick reply Jum…. I tried it in my emulator with k-9 mail client… its nt working.
July 21st, 2010 @ 3:27 pm
Excellent post, thank you very much!
| June 21st, 2010 @ 12:36 pm
Hi,
I tried your second code to send html message and its working fine for gmail but its not working for HTC email.where in nothing gets displayed in body of the mail.I tried it in HTC Hero.
| June 22nd, 2010 @ 3:02 am
It could be that the HTC email client that is included in the Hero does not support HTML email. Unfortunately, I don’t have a Hero to test with.
| June 23rd, 2010 @ 6:35 pm
Thanks for the quick reply Jum…. I tried it in my emulator with k-9 mail client… its nt working.
| July 21st, 2010 @ 3:26 pm
hi thanks fr the amazing tut..
i m facing a problem..the link which i want to send comes as hyperlink while sending mail..ie i c it dt its a hyperlink
BUT on recieving mail it gets converted back to text..any idea what might be happening??r i might b doing wrng
it would b really great if u could help
thanks in advance
| July 26th, 2010 @ 2:04 pm
i m trying to send mail through gmail
| July 26th, 2010 @ 2:17 pm
I would take a look at your sent box to see if it is still HTML there. Otherwise it may be an issue with the receiving email box only viewing the plain text version.
| July 26th, 2010 @ 2:20 pm
thank u fr such a quick reply..
it possibly cannot be a case f receiving email in text version becoz…
the mail i m sending has a share link which is obtained by WebView.getUrl() ..
which is seen as text during sending mail..but becomes hyperlink on being recieved
n i want to send another link in d mail so i make it a hyperlink using
link ..dis link is shown as hyperlink whn i m sending ..but converts to text on being recieved
totally confused!!
| July 26th, 2010 @ 2:29 pm
hmm..let me b more precise
String val=text+ “ click here“;
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,title);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(val));
emailIntent.setType(“text/html”);
startActivity(Intent.createChooser(emailIntent, “Send mail…”));
what m i missing??pls help
| July 26th, 2010 @ 2:57 pm
I’m not sure if the order is significant, but my first guess would be to put the setType call before adding the extras.
July 27th, 2010 @ 11:05 pm
hi thanks fr the reply,
i hv already tried d code with setType bfore extras becoz dt ws d only diffrence in our codes i could point out…no effect..still d same i c link i want to send as hyperlink while composing mail..whch changes back to text on being sent
also frm wht i hv searched on net i guess gmail sets mime type to default plain/text while sending mssg…due to which only text is recived..loads f ppl hv faced dis problem…nt sure if i m crrct on dis
1)http://code.google.com/p/android/issues/detail?id=3951
2)http://forums.androidandme.com/topic/sending-email-with-html-in-body
also i tried using ur app cbs news..share app function wrked perfectly in it..u hv used d same above code fr dt..r some change..
pls help!
| July 28th, 2010 @ 9:45 am
That’s strange that the CBS News app would work correctly but your code didn’t. My next guess would have been something with the configuration of the email client, but the code used in it is the same with the one exception of putting the startActivity(emailIntent) in a try/catch, which shouldn’t affect the email itself. My only other thought would be to verify your version of Java (the computer I’m on now has 1.6.0_18), ensure your Android SDK is up to date, and possibly try other build targets. It might be easiest to just create a new project with a simple activity that triggers the above code in its onCreate method to see if that works. If it does, then start making changes to it one at a time to bring it closer to what you are trying to use now that isn’t working. If it doesn’t work, then it must be a factor outside your code.
| July 28th, 2010 @ 10:11 am
Hi,
I try to use html formated text mail.
I try with the second code and it works fine.
But I have one problem. I want to send the html with hyperlink.
I try with code like
Example
But when I send the mail, it come only Example not the hyperlink.
What can I do to send with hyperlink.
| August 6th, 2010 @ 8:12 am