1

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

Laser
  • 93
  • 2
  • 9

1 Answers1

0

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.

Community
  • 1
  • 1
Jordan
  • 6,083
  • 3
  • 23
  • 30
  • Thanks, I tried with a hardcoded address and it works great, however, I'm not sure this is the solution for me. This relies on a hard coded user, password, and from email address but I want the email to send from the user's email without them needing to fill it in themselves. I certainly don't want to release it with my test information in the code. – Laser Apr 15 '11 at 17:28
  • I opted to prompt for the users email and password the first time and save them so this now works perfectly for me, thanks. – Laser Apr 15 '11 at 21:02