How can I send emails from my Android application?


Question

I am writing an application for Android. How can I send an email from it?

1
503
9/6/2014 8:34:43 PM

Accepted Answer

The best (and easiest) way is to use an Intent:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

Otherwise you'll have to write your own client.

949
8/8/2014 2:21:11 AM

Use .setType("message/rfc822") or the chooser will show you all of the (many) applications that support the send intent.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon