This code starts the email activity with pre-set data. On the emulator it might get a "No application can perform this action" failure, although it works on a real phone. Code picked up on anddev
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
/* Send it off to the Activity-Chooser */
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
7 Comments
Hi, I need send email like HTML. So I try emailIntent.setType("text/html"); but email isn't formated like HTML page. I see HTML tags. Do you have any idea how can I do it?
Exactly what I was looking for. Works well! Thanks, feri
a typo: Intent.createChooser(intent... should be Intent.createChooser(emailIntent...
Thanks for the tip -- the typo is corrected! :)
Intent intent = new Intent(Intent.ACTION_SEND); String[] tos = { "shenrenkui@gmail.com" }; String[] ccs = { "shenrenkui@gmail.com" }; intent.putExtra(Intent.EXTRA_EMAIL, tos); intent.putExtra(Intent.EXTRA_CC, ccs); intent.putExtra(Intent.EXTRA_TEXT, "body"); intent.putExtra(Intent.EXTRA_SUBJECT, "subject"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client");
This is perfect. I was looking for code to do just this.
Just as a note this won't work on the emulator. You'll need to push it out to a device for emailing to work.