如何在Android中发送HTML Mail

时间:2012-02-03 11:07:24

标签: android html email

IO想在android中以html格式发送电子邮件。我可以通过gmail客户端发送邮件,但是当我使用任何其他客户端时,我无法获得html的样式。我使用了下面的代码

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");

i.putExtra(Intent.EXTRA_SUBJECT, "TestMail");
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p><b>Some Content</b></p>"));

try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(EmailHtmlActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}

2 个答案:

答案 0 :(得分:1)

试试这个

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

答案 1 :(得分:0)

尝试这个我不确定,但它可能对你有所帮助..

startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND).setType("message/rfc822")
.putExtra(Intent.EXTRA_SUBJECT, subject)
.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(new String().concat("YOUR MESSAGE")), 
 "Send your email in:"));

感谢。