Send Email On Start Activity

This example explains how you can send email by using ACTION_SEND on start activity.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it SendEmailExample.

2.) Write following into main.xml:

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SendEmailExampleActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>

 

3.) Run for output.

Steps:

1.) Create a project named SendEmailExample and set the information as stated in the image.

Build Target: Android 4.4
Application Name: SendEmailExample
Package Name: com.example.SendEmailExample
Activity Name: SendEmailExampleActivity

sendemail1

2.) Open SendEmailExampleActivity.java file and write following code there:

 

package com.example.sendemailexample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;

public class SendEmailExampleActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String emailList[] = {"chetanagaonshindhe@gmail.com"};

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailList);
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Text");
startActivity(Intent.createChooser(intent, "Choice email App"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.send_email_example, menu);
return true;
}
}

 

 

3.) Compile and build the project.

Output

sendemail2