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_BCC: email addresses for blind carbon copy
- EXTRA_CC: email addresses for carbon copy
- EXTRA_EMAIL: email addresses for recipients
- EXTRA_HTML_TEXT: Supply an alternative to EXTRA_TEXT as HTML formatted text
- EXTRA_STREAM: URI holding a stream of data supplying the data that are sent
- EXTRA_SUBJECT: The subject of an email
- EXTRA_TEXT: The message body of the email
- EXTRA_TITLE: The 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