Thursday, 23 July 2015

Send An Email In Android

Here I am going to explain how to send email using android.

For email sending you must need an Internet permission in your application. You can send an email via Share Intent.

You can write permission like: <uses-permission android:name="android.permission.INTERNET"/>

For Example:

String to = "";
String subject = "My Message";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, et_message.getText().toString().trim());
 
//need this to prompts email client only
email.setType("message/rfc822");
 
startActivity(Intent.createChooser(email, "Choose an Email Client :"));

This code is send a request to your email composer for send an email.

Email Intent have some more options like following. You can use it according to your requirement.

  • EXTRA_BCCemail addresses for blind carbon copy
  • EXTRA_CCemail addresses for carbon copy
  • EXTRA_EMAILemail addresses for recipients
  • EXTRA_HTML_TEXTSupply an alternative to EXTRA_TEXT as HTML formatted text
  • EXTRA_STREAMURI holding a stream of data supplying the data that are sent
  • EXTRA_SUBJECTThe subject of an email
  • EXTRA_TEXTThe message body of the email 
  • EXTRA_TITLEThe title that is shown when the user has to choose an email client.
Output:




















You can download the full source code from here. SendEmail

Enjoy Coding...!!!

No comments:

Post a Comment