发送HTML邮件使用的是Android的意图的是、意图、邮件、HTML

2023-09-12 23:38:18 作者:软软可可爱了

我已经生成的HTML code(完整的< HTML><身体GT;< / BODY>< / HTML> 标签)作为串。现在,我想送这个HTML code为HTML邮寄。我的code是如下。

 意向意图=新的意图(Intent.ACTION_SEND);
intent.setType(text / html的);
intent.putExtra(Intent.EXTRA_EMAIL,新的String [] {me@mydomain.com});
intent.putExtra(Intent.EXTRA_SUBJECT,我想购买下);
intent.putExtra(Intent.EXTRA_TEXT,purchaseOrder中());
startActivity(Intent.createChooser(意向,发送邮件));
 

purchaseOrder中()是通过我有完整的HTML code中的字符串的方法。不过,虽然Gmail的客户端打开我的Nexus1但与所有的HTML标签,而不是实际的HTML视图中的字符串。我尝试以下,但得到的错误。 Gmail的崩溃。

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

解决方案 使用魔方网表发送自定义模板的HTML邮件

这对我的作品:

 最终意图emailIntent =新的意图(android.content.Intent.ACTION_SEND);
emailIntent.setType(text / html的);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(体));
startActivity(Intent.createChooser(emailIntent,电子邮件:));
 

不过,我已经注意到,内嵌样式和图像标记被忽略了......

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

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

解决方案

This works for me:

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...

 
精彩推荐
图片推荐