使用 Android Intent 发送 HTML 邮件 [英] Send HTML mail using Android intent

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

问题描述

我已经生成了一个 HTML 代码(完整的 </body></html> 标签)作为字符串.现在我想将此 HTML 代码作为 HTML 发送到邮件.我的代码如下.

I have generated an HTML code(complete with <html><body></body></html> tags) as a String. Now I want to send this HTML code as HTML to mail. My code is as below.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"me@mydomain.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "I would like to buy the following");
intent.putExtra(Intent.EXTRA_TEXT, purchaseOrder());
startActivity(Intent.createChooser(intent, "sending mail"));

其中 purchaseOrder() 是向我传递具有完整 HTML 代码的字符串的方法.但是,尽管 GMail 客户端在我的 Nexus1 上打开,但它具有包含所有 HTML 标签的字符串,而不是实际的 HTML 视图.我尝试了以下但出错了.GMail 崩溃了.

Where the purchaseOrder() is the method which passes me the string having full HTML code. But though the GMail client opens on my Nexus1 but it has the String with all HTML tags and not the actual HTML view. I tried the following but got error. The GMail crashed.

intent.putExtra(Intent.EXTRA_STREAM, purchaseOrder());

推荐答案

这对我有用:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(emailIntent, "Email:"));

但我注意到内联样式和图像标签被忽略了...

But I've notice that inline styles and image tags are being ignored...

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

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