发送 HTML 邮件

huangapple 未分类评论48阅读模式
英文:

Send html emails

问题

以下是翻译好的内容:

这个主题有很多关于问题和答案,但似乎没有一个能够解决我的问题。我在Google中搜索了“在Android Java中发送HTML电子邮件”并按照所有链接进行了尝试,但都没有成功(来自stackoverflow和其他网站)。我想从我的Android应用和Gmail应用程序中发送HTML电子邮件。我使用以下代码来实现,但我总是收到纯文本电子邮件:

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mysubject);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
StringBuilder sbContent = new StringBuilder();
sbContent.append("<p>Text <strong>with html</strong></p>");
emailIntent.putExtra(Intent.EXTRA_TEXT, HtmlCompat.fromHtml(sbContent.toString(), HtmlCompat.FROM_HTML_MODE_LEGACY));
startActivity(Intent.createChooser(emailIntent, ""));

我尝试过将类型更改为“text/plain”,将EXTRA_TEXT更改为EXTRA_HTML_TEXT,以及其他一些尝试,但都没有成功。是否有人有如何实现此功能的示例?

英文:

There are a lot of questions and answer about this topic but none of them seems to work. I have search in Google about "send html email Android Java" and followed all links without success (from stackoverflow and from other sites). I want to send an HTML email from my android app and Gmail app. I use the next code to do it but I always get a text email:

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType(&quot;message/rfc822&quot;);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mysubject);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
StringBuilder sbContent = new StringBuilder();
sbContent.append(&quot;&lt;p&gt;Text &lt;strong&gt;with html&lt;/strong&gt;&lt;/p&gt;&quot;);
emailIntent.putExtra(Intent.EXTRA_TEXT, HtmlCompat.fromHtml(sbContent.toString(), HtmlCompat.FROM_HTML_MODE_LEGACY));
startActivity(Intent.createChooser(emailIntent, &quot;&quot;));

I've tried changing type to "text/plain", EXTRA_TEXT with EXTRA_HTML_TEXT, and some other attemps, but without success. Does anyone have an example of how to do it?

huangapple
  • 本文由 发表于 2020年5月4日 23:56:11
  • 转载请务必保留本文链接:https://java.coder-hub.com/61596381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定