Copy Code code as follows:
Package com.example.myapi.email;
Import java.util.ArrayList;
Import java.util.List;
Import Android.content.Context;
Import android.content.Intent;
Import Android.net.Uri;
public class Sendemailutils {
Private Sendemailutils () {}
private static sendemailutils instance;
public static Sendemailutils getinstance () {
Synchronized (Sendemailutils.class) {
if (instance = = null) {
Instance = new Sendemailutils ();
}
}
return instance;
}
/**
* This is a simple test, does not support with attachments, many people, CC send and so on.
* @param context
*/
public void SendEmail {
Intent Intent = new Intent ();
Intent.setdata (Uri.parse ("mailto:"));
/* Set the title of the message/*
Intent.putextra (Intent.extra_subject, "Don't be nervous, this is just a test!") ");
/* Set the content of the message * *
Intent.putextra (Intent.extra_text, "Test open the system mailbox and automatically populate the mailbox with the headers and contents sent, and send the message,");
Start calling
Context.startactivity (Intent);
}
/**
* e-mail, with CC, and secret send, and with the last attachment
* @param context
*/
public void Sendemailduo {
Intent Intent = new Intent (intent.action_send);
Intent.setdata (Uri.parse ("mailto:"));
String[] tos = {"Yw.1@163.com"};
String[] CCS = {"Yw.2@163.com"};
String[] BCCs = {"Yw.3@163.com"};
Intent.putextra (Intent.extra_email, TOS); Received by
Intent.putextra (INTENT.EXTRA_CC, CCS); CC this
Intent.putextra (INTENT.EXTRA_BCC, BCCs); The Secret Send this
Intent.putextra (Intent.extra_text, "Mail Content");
Intent.putextra (Intent.extra_subject, "mail title");
Intent.putextra (Intent.extra_stream, Uri.parse ("file:///mnt/sdcard/a.jpg"));
Intent.settype ("image/*");
Intent.settype ("message/rfc882");
Intent.createchooser (Intent, "Choose Email Client");
Context.startactivity (Intent);
}
/**
* Multiple Attachment Send
* @param conext
*/
public void Sendfujian (context conext) {
Intent Intent = new Intent (intent.action_send_multiple);
String[] tos = {"Way.ping.li@gmail.com"};
String[] CCS = {"Way.ping.li@gmail.com"};
Intent.putextra (Intent.extra_email, TOS);
Intent.putextra (INTENT.EXTRA_CC, CCS);
Intent.putextra (Intent.extra_text, "body");
Intent.putextra (Intent.extra_subject, "SUBJECT");
list<uri> Imageuris = new arraylist<uri> ();
Imageuris.add (Uri.parse ("file:///mnt/sdcard/a.jpg"));
Imageuris.add (Uri.parse ("file:///mnt/sdcard/b.jpg"));
Intent.putextra (Intent.extra_stream, Imageuris);
Intent.settype ("image/*");
Intent.settype ("message/rfc882");
Intent.createchooser (Intent, "Choose Email Client");
Conext.startactivity (Intent);
}
}