tags:

views:

487

answers:

6

Hi, i found a way to send plain text email using intent:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new     
String[]{"[email protected]"}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test");

But I need to send HTML formatted text.
Trying to setType("text/html") doesn't work.

A: 

What about just trying to add some html in the text area?

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "<strong>Test</strong>");
EpicDewd
Don't work. It looks as plain text.
Orsol
+1  A: 

I haven't (yet) started Android development, but the documentation for the intent says that if you use EXTRA_TEXT, the MIME type should be text/plain. Seems like if you want to see HTML, you'd have to use EXTRA_STREAM instead...

Chris Shaffer
This works partly. I attached file but it MIME type always text\plain in resulting letter. I tried to set emailIntent.setType("html/text"); with no luck.
Orsol
+1  A: 

Related SO question:

http://stackoverflow.com/questions/2020088/android-sending-email-without-using-the-default-android-appbuiltin-email-appli

fupsduck
Preferable to use account settings already added by user.
Orsol
+1  A: 

You can pass Spanned text in your extra. To ensure that the intent resolves only to activities that handle email (e.g. Gmail and Email apps), you can use ACTION_SENDTO with a Uri beginning with the mailto scheme. This will also work if you don't know the recipient beforehand:

final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
    .toString())
);
antnerves
A: 

how can i add a picture in this mail, not attached but in the email!!

i can't see the picture !!!!

tatou android
A: 

antnerves, Thanks for you method. It seems that this is the only method with EXTRA_TEXT and Html. Use EXTRA_STREAM not work.

landry