Send Email with Intent - Android android.content

Android examples for android.content:Intent

Description

Send Email with Intent

Demo Code

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

public class Main {

  public static void SendEmail(Activity currentActivity, String[] recipients, String subject, String body) {
    SendEmail(currentActivity, recipients, subject, body, "Send mail...");
  }/*from   w w  w .java 2s.  c o m*/

  public static void SendEmail(Activity currentActivity, String[] recipients, String subject, String body,
      String chooserTitle) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, recipients);
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, body);
    try {
      currentActivity.startActivity(Intent.createChooser(i, chooserTitle));
    } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(currentActivity, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
  }

}

Related Tutorials