Send email in Android using Intents - example

                               Its very simple to develop email App in Android.  Before the code, let me explain the stuffs used here, that will help you to understand the Android email application clearly. Basically this example tries to pass data between activities, in this way various functionalities can be achieved, lets see how to send email as far now.

               Intent is an abstract description of an operation to be performed. When you construct an intent, you must specify the action you want the intent to "trigger." Android defines several actions, including ACTION_SEND which, as you can probably guess, indicates that the intent is sending data from one activity to another. To send data to another activity, all you need to do is specify the data and its type, the system will identify compatible receiving activities and display them to the user (if there are multiple options) or immediately start the activity (if there is only one option). We need to call Intent.createChooser() , Android will always display the chooser
                 The most straightforward and common use of the ACTION_SEND action is sending text content from one activity to another. Here is the code to implement this type of sharing.

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, message); 

Email App

Then we need to choose the email client with this code
startActivity(Intent.createChooser(email, "Select Email Client"));

This will invoke the Email client with To, Subject and Message text as shown below.

Select email client
Download eclipse project here

Download Email Application here  

package com.example.emailapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    Button btnSend;
    EditText To;
    EditText Subject;
    EditText Message;
    public void onCreate(Bundle savedInstanceState) {
        To = (EditText) findViewById(;
        Subject = (EditText) findViewById(;
        Message = (EditText) findViewById(;
        btnSend = (Button) findViewById(;
        btnSend.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              String to = To.getText().toString();
              String subject = Subject.getText().toString();
              String message = Message.getText().toString();
              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, message);          
              startActivity(Intent.createChooser(email, "Select Email Client"));

Gmail Client

Finally this will invoke the email client in your mobile and we can send email. Thats it, we have developed application to send email in Android.

Kindly note this application will work only on your mobile, NOT in android emulator.




  1. Replies
    1. File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
      + "/FolderName" + "/" + "filename.ext");

  2. interesting!
    can you please do a example when you use IMAP (imaps?) or (in worst case) POP3 to log-in to Gmail-email and fetch email from, example a "date x and later"?
    and list those, or list how many email was found?

    I am trying just that, but fail, over and over again:-(
    and all I find is send mail or "non working in android-java"-java example.
    I can fetch with pop3 in plain java but this is not "antroid-java-dalvik.." :-(
    some errorcode:
    03-27 10:44:24.943: D/AndroidRuntime(557): Shutting down VM
    03-27 10:44:24.943: W/dalvikvm(557): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
    03-27 10:44:25.063: D/dalvikvm(557): GC_CONCURRENT freed 269K, 5% free 7062K/7431K, paused 7ms+7ms
    03-27 10:44:25.063: E/AndroidRuntime(557): FATAL EXCEPTION: main
    03-27 10:44:25.063: E/AndroidRuntime(557): java.lang.IllegalStateException: Could not execute method of the activity
    03-27 10:44:25.063: E/AndroidRuntime(557): at android.view.View$1.onClick(

    best regards