I'm building a very simple android application that creates a string based on a bunch of user inputs. I want to give the user the ability to email themselves the string from the app.
I come from a php background where this is very straight forward: there's a function that takes the "to" address, body, subject etc and conveniently sends the email from php:
mail($to,$subject,$message,$headers)
This is basically what I'd like to replicate in the Android environment. I've had some success with things like the below but this just opens the users email client
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String emailTo = userEmail;
String emailSubject = "Subject Line";
String emailBody = userString;
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailTo);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,emailSubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailBody));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Finally i tried calling out to a php script to do the send:
String phpSend = "http://www.MyPHPSendScript.com?emailbody=userString";
try {
URL url = new URL(phpSend);
url.openConnection().getContent();
} catch (Exception e) {
out.println("Failed to send email");
}
But a) this failed and b) it seems like a bit of a hack...
Does anyone have any thoughts/suggestions?
Thanks, The Grinch