简体   繁体   中英

Send HTML e-mail with Intent

I want to send a HTML e-mail when an user decides to share my app. I'm using HTML in order to have a customised and appellative message.

First approach, I tried to create a String with my HTML (inline style) using Html.fromHtml but when I received the e-mail it was pure txt, no customization.

Second approach, send a HTML file attached. The problem with this approach is that the HTML is not showed until the user opens the attach.

What's the best solution, is it possible? Thanks!

您可以使用此方法Html.fromHtml(String);完成任务Html.fromHtml(String);

Html.fromHtml("<font color='#ff123456'>text</font>")

You can pass Spanned text in your extra. To ensure that the intent resolves only to activities that handle email (eg 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())
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM