如何发送 HTML 电子邮件 [英] How to send HTML email

查看:45
本文介绍了如何发送 HTML 电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一种使用 Intent 发送纯文本电子邮件的方法:

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[]{"example@mail.com"}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test");

但我需要发送 HTML 格式的文本.
尝试 setType("text/html") 不起作用.

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

推荐答案

您可以在额外内容中传递 Spanned 文本.为确保意图仅解析处理电子邮件的活动(例如 Gmail 和电子邮件应用程序),您可以使用 ACTION_SENDTO 和以 mailto 方案开头的 Uri.如果您事先不知道收件人,这也适用:

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())
);

这篇关于如何发送 HTML 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆