开发者

Android Email HTML from webpage

I am writing an android app and at some point I need to send an email to a user specified address. To do this I am opening an email app and filling in the subject and body allowing the user to fill in the recipient. The email being sent should be html that I pull from a pre specified webpage. Pulling the html from the web is simple, but won't display properly when emailed. The code I am using to open the email app is:

intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.E开发者_Python百科XTRA_SUBJECT, getString(R.string.shareSubject));
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(intent, "Email:"));

This should allow the user to select their email client and send an html email if the selected client supports it. I have been testing with the gmail app which has been reported to support it, but when the email is received it is in plain text.

If it helps, the code I am essentially using to get the code is:

String input;
String body = "";
try
{
    URL url = new URL("<url>");
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    while((input = in.readLine()) != null)
        body = body + input;    
}
catch(MalformedURLException e)
{

}
catch(IOException e)
{

}

I'm not sure why this is failing, everything I have looked at says that the gmail app supports sending html emails and that this is the code to do it. Any help would be appreciated.


Your question is very similar to the question Send HTML mail using Android intent.

You can see a bunch of suggested solutions there. I'd prefer mdaddy's solution of the Android-specific version of the JavaMail API available here:

http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android

This way, you wouldn't have to open (or rely on) any external mail application. Instead, you could take the email address as input from within your application and do all the sending behind the scenes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜