Skip to content
Related Articles

Related Articles

Improve Article

How to send an Email from your Android App?

  • Difficulty Level : Medium
  • Last Updated : 17 Jan, 2020
Geek Week

In this article, you will make a basic android application which can be used to send email through your android application.

You can do so with the help of Intent with action as ACTION_SEND with extra fields:

  • email id to which you want to send mail,
  • subject of email and
  • body of the email.

Basically Intent is a simple message object that is used to communicate between android components such as activities, content providers, broadcast receivers and services, here use to send the email.

This application basically contains one activity with EditText to take input of email address, subject and body of the email from user and button to send that email.

  • Step 1. activity_main.xml
    activity_main.xml contains a Relative Layout which contains three Edit texts for receiver mail id, other for the subject of the mail and last one for the body of the email and three TextViews for the label and a button for starting intent or sending mail:


    <?xml version="1.0" encoding="utf-8"?>
    <!--Relative Layout-->
        <!--Edit text for email id-->
        <!--Edit text for email subject-->
        <!--Edit text for email body-->
        <!--text Views for label-->
            android:text="Send To:" 
            android:text="Email Subject:" 
            android:text="Email Body:"
        <!--Button to send email-->
            android:text="Send email!!"

  • Step 2.
    In Main activity Intent object is created and its action is defined to ACTION_SEND to send email, with Intent three extra fields are also added using putExtra function.These fields are:
    • Email of receiver
    • Subject of email
    • Body of email

    setOnClickListener is attached to button with intent object in it to make intent with action as ACTION_SEND to send email and intent type as shown in code.

    Here is complete java code to send email through intent from android application:

    package com.geeksforgeeks.phonecall;
    import android.os.Bundle;
    import android.content.Intent;
    import android.widget.EditText;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    public class MainActivity extends AppCompatActivity {
        // define objects for edit text and button
        Button button;
        EditText sendto, subject, body;
        protected void onCreate(Bundle savedInstanceState)
            // Getting instance of edittext and button
            sendto = findViewById(;
            subject = findViewById(;
            body = findViewById(;
            button = findViewById(;
            // attach setOnClickListener to button
            // with Intent object define in it
            button.setOnClickListener(new OnClickListener() {
                public void onClick(View view)
                    String emailsend = sendto.getText().toString();
                    String emailsubject = subject.getText().toString();
                    String emailbody = body.getText().toString();
                    // define Intent object
                    // with action attribute as ACTION_SEND
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    // add three fiels to intent using putExtra function
                                    new String[] { emailsend });
                    intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
                    intent.putExtra(Intent.EXTRA_TEXT, emailbody);
                    // set type of intent
                    // startActivity with intent with chooser
                    // as Email client using createChooser function
                                           "Choose an Email client :"));


Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!

My Personal Notes arrow_drop_up
Recommended Articles
Page :