Android Send Email


Android Send Email

The intent refers to a simple message object is used for communicating with Android components such as content providers, activities, broadcast receivers, and services and is used for sending emails in this case.

Before beginning the Email Activity, you must be familiar with the Email feature and intent. The intent is the process of moving data from one component to another within or outside the application.

To send an email from your app, you don't have to create one from scratch; you may use one that already exists, such as Android's default Email app, Outlook, Gmail, K-9 Mail, and so on.

To accomplish this, we'll need to create an Activity that launches an email client with the appropriate action and data, based on an implicit Intent. In this example, we'll use an Intent object to send an email from our app, which will start existing email clients.

Intent Object - Email Sending Action

The ACTION_SEND action will be used to launch an email client on your Android smartphone. The syntax for creating an intent using the ACTION_SEND action is as follows.

Intent emailIntent = new Intent(Intent.ACTION_SEND);

Intent Object - Data/Type to send Email

To send an email, use the setData() method to specify the mailto: URI and the setType() method to define the data type as text/plain, as shown below:

emailIntent.setData(Uri.parse("mailto:")); 

emailIntent.setType("text/plain");  

Intent Object - Extra to send Email

Before delivering the intent to a target email client, Android offers built-in functionality for adding TO, SUBJECT, CC, TEXT, and other fields to the intent.