In this Android tip, I am going to show how to code in Android to send an e-mail message to a recipient. When you create an application that contains the sending e-mail message functionality, this tip might be useful to you.
Android provides a simple way to send the e-mail message programmatically. In your code, first you need to create an Intent object with the Intent.ACTION_SEND value passed to the Intent class's constructor.
//create an Intent object to send e-mail message
Intent intent=new Intent(Intent.ACTION_SEND);
Then you can specify the mine type of the e-mail data with the setType method as shown below. This method accepts a string that represents the mine type of the e-mail data. Here are the common mine types used in Android:
For example, to send an e-mail data of the image type, you can specify the mine type as below:
//specify the mine type of the e-mail message
If you want to send an e-mail data of any mine type or unknown type, the mine type string will be */*.
After you specified the mine type of the e-mail data, you will set recipients' e-mail addresses, subject, message, and file attachment of the e-mail by using the putExtra method. This method accepts pairs of keys and values.
//put the recipient e-mail addresses in the intent object
//put the subject in the intent object
//put the message in the intent object
intent.putExtra(Intent.EXTRA_TEXT,"This is an e-mail sent from Android mobile app.");
//create a Uri object to for the attached file path
//put attached file in the intent object
//query available e-mail clients and start sending e-mail message
List<ResolveInfo> vapps=pm.queryIntentActivities(intent, 0);
Posted by: Dara | post date: 06-14-2014 | Subject: Android Apps Development
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: