简体   繁体   中英

Why isn't this code to send an HTML e-mail using an Intent working?

Hi I am trying to send mail from my android application but I am not getting proper mail in my inbox my code is here please help me.

Spanned mailBody2 = Html.fromHtml("<body><table width=\"200\" border=\"1\"><tr bgcolor=\"#3399FF\"><td>hi</td><td>gaurav</td><td>patel</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></body>");

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[] { "jansodariya@gmail.com" };
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Summ");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,mailBody2);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Change

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,mailBody2);

to

String mailtext="<body><table width=\"200\" border=\"1\"><tr bgcolor=\"#3399FF\"><td>hi</td><td>gaurav</td><td>patel</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></body>";  

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(mailtext));

This should work. refer this link . Hope it helps.

You cannot do this. You only can send text trough an email. You must use php to send formatted mails. Please read here also Send HTML mail using Android intent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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