Friday, July 1, 2011

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:



(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:



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. As long as the mail app that is selected is able to properly handle the Intent (e.g., the Gmail app can, the default mail app cannot), then HTML email can be sent.

No comments:

Post a Comment