我正在尝试使用Intent发送html邮件。在作曲家中它以html格式显示,但在收件人端,它显示为普通文本。我必须发送图像和带有超链接的文本。 作曲家的截图看起来像这样
以下是我到目前为止所尝试的内容,
public class Sendingamail extends Activity {
/** Called when the activity is first created. */
Button send;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
send=(Button) findViewById(R.id.emailsendbutton);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
String html = "<!DOCTYPE html><html><body><a href=\"http://www.google.com\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hhhhhhhh");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(html));
Sendingamail.this.startActivity(emailIntent);
});
}
}
答案 0 :(得分:1)
这对我有用:
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())
);
答案 1 :(得分:0)
String text = "<body><b>" +heading +
"<br>..............................</b><br><br>" +
"<b><font color='green'>Posted Date :</font></b><br>"+ postedDate + "<br><br>"
+ "<b><font color='green'>Posted By :</font></b><br>" + postedBy+ "<br><br>"
+ "<b><font color='green'>Description :</font></b><br>"+ desc + "<br><br>"
+ "<b><font color='green'>Post type :</font></b><br>"
+ postType + "</body>";
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));
startActivity(sendIntent);
答案 2 :(得分:0)
几天前我遇到了同样的问题。关于它的代码没有什么可以做的,因为只有当您使用的邮件客户端能够处理默认电子邮件和gmail客户端无法使用的所有html和css内容时,才会显示html内容。所以你可以使用java mail api发送html邮件,或者你必须寻找支持完整html的邮件客户端。请看一下here