简体   繁体   English

使用Intent发送HTML电子邮件

[英]Send HTML e-mail with Intent

I want to send a HTML e-mail when an user decides to share my app. 当用户决定共享我的应用程序时,我想发送HTML电子邮件。 I'm using HTML in order to have a customised and appellative message. 我使用HTML是为了获得自定义的好听的消息。

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. 第一种方法,我尝试使用Html.fromHtml用HTML(内联样式)创建一个String,但是当我收到电子邮件时,它是纯txt,没有自定义。

Second approach, send a HTML file attached. 第二种方法,发送一个附加的HTML文件。 The problem with this approach is that the HTML is not showed until the user opens the attach. 这种方法的问题在于,直到用户打开附件,HTML才会显示。

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. 为确保该意图仅解决处理电子邮件的活动(例如Gmail和电子邮件应用程序),您可以将ACTION_SENDTO与以mailto方案开头的Uri一起使用。 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())
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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