Android sending email

In this tutorial we will learn how to send an email from android application. For sending an email in android, you don’t need to implement email client from beginning, you just need to use Intent to send email using existing email application which is installed in your phone.

You need to use ACTION_SENDTO in Intent to open email application directly instead of a popup which will contain all application which allows sharing.

Intent intent = new Intent(Intent.ACTION_SENDTO);

Adding recipient address to intent

intent.putExtra(Intent.EXTRA_EMAIL, TO); //TO will be a string array

If you want to add CC to email

intent.putExtra(Intent.EXTRA_CC, CC); //CC will be a string array

Adding subject

intent.putExtra(Intent.EXTRA_SUBJECT, "Android Email");

Adding content to email

intent.putExtra(Intent.EXTRA_TEXT, "Android Email Content");

For complete code use the below function

Note : Use your recipient email ids in To and CC array in the below code

public void sendEmail() {

String[] TO = {"abc@gmail.com"};
String[] CC = {"efg@outlook.com"};

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, TO); //TO will be a string array
intent.putExtra(Intent.EXTRA_CC, CC); //CC will be a string array
intent.putExtra(Intent.EXTRA_SUBJECT, "Android Email");
intent.putExtra(Intent.EXTRA_TEXT, "Android Email Content");

if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}

}

About the author

Hi guys, i am the author of codesfor. I am a B.Tech graduate currently working as an App developer. Apart from job i am a blogger and a freelancer.

Add a Comment

Your email address will not be published. Required fields are marked *