Android send email using intent | Email with attach text

How to send email in android studio using intent

Send email from you own application. Sending mail help you also in sending user 
feedback to developer. Set your default feedback email to send instant email just type 
user comment or problem in your application. Android send email is easy followed by 
"message/rfc822" this will fetch all the email sending browser. Learn more about sending
email from Android official page.

package write your package name here;

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

public class MainActivity extends AppCompatActivity {
    EditText mailTo,mailSubject,mailMessage;
    Button sendEmail;
    protected void onCreate(Bundle savedInstanceState) {

        mailTo = (EditText)findViewById(;
        mailSubject = (EditText)findViewById(;
        mailMessage = (EditText)findViewById(;

        sendEmail = (Button)findViewById(;
        sendEmail.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                //Get and Set editText value in String.
                String to = mailTo.getText().toString();
                String subject = mailSubject.getText().toString();
                String message = mailMessage.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);

                //This will show prompts of email intent
                startActivity(Intent.createChooser(email, "Choose an Email sender :"));


    public boolean onCreateOptionsMenu(Menu menu) {
        // For menu in Title bar
        getMenuInflater().inflate(, menu);
        return true;

Visit NextGenEarn Blog for all new code snippets no deprecated code.

Add a Comment

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