Android calls the system's email function for a small example _android

Source: Internet
Author: User

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);
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.