Open the email client and send email - Android Intent

Android examples for Intent:Send Email

Description

Open the email client and send email

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.Intent;

import android.text.TextUtils;

public class Main {
    /**//from   ww  w .j av  a2  s. c om
     * Open the email client and send email
     *
     * @param context Context
     * @param email   The email address
     * @param subject The email receiver
     * @param content The email content
     */
    public static void sendEmail(Context context, String email,
            String subject, String content) {
        try {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("plain/text");
            String address[] = new String[] { email };
            if (!TextUtils.isEmpty(subject)) {
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            }
            if (!TextUtils.isEmpty(content)) {
                intent.putExtra(Intent.EXTRA_TEXT, content);
            }
            intent.putExtra(Intent.EXTRA_EMAIL, address);
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials