How to call the system Email to send emails in Android Development (multiple call methods)

Source: Internet
Author: User

We all know that calling other programs in Android for relevant processing is almost all using Intent, so Email is no exception.

In Android, there are three types of Intent for calling Email:
Intent. ACTION_SENDTO send without attachment
Intent. ACTION_SEND send with attachment
Intent. ACTION_SEND_MULTIPLE send with multiple attachments

Of course, the so-called call Email only means that the Email can receive Intent and do these things. Other applications may also implement related functions. Therefore, during execution, the Select box is displayed.

1. Use SENTTO to send
[Java]Copy codeThe Code is as follows: Intent data = new Intent (Intent. ACTION_SENDTO );
Data. setData (Uri. parse ("mailto: way.ping.li@gmail.com "));
Data. putExtra (Intent. EXTRA_SUBJECT, "this is the title ");
Data. putExtra (Intent. EXTRA_TEXT, "this is content ");
StartActivity (data );

Intent data = new Intent (Intent. ACTION_SENDTO );
Data. setData (Uri. parse ("mailto: way.ping.li@gmail.com "));
Data. putExtra (Intent. EXTRA_SUBJECT, "this is the title ");
Data. putExtra (Intent. EXTRA_TEXT, "this is content ");
StartActivity (data );

You can set the mail parameters to putExtra in Intent.

2. SEND with SEND
[Java]Copy codeThe Code is as follows: Intent intent = new Intent (Intent. ACTION_SEND );
String [] tos = {"way.ping.li@gmail.com "};
String [] ccs = {"way.ping.li@gmail.com "};
String [] bccs = {"way.ping.li@gmail.com "};
Intent. putExtra (Intent. EXTRA_EMAIL, tos );
Intent. putExtra (Intent. EXTRA_CC, ccs );
Intent. putExtra (Intent. EXTRA_BCC, bccs );
Intent. putExtra (Intent. EXTRA_TEXT, "body ");
Intent. putExtra (Intent. EXTRA_SUBJECT, "subject ");

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 ");
StartActivity (intent );

Intent intent = new Intent (Intent. ACTION_SEND );
String [] tos = {"way.ping.li@gmail.com "};
String [] ccs = {"way.ping.li@gmail.com "};
String [] bccs = {"way.ping.li@gmail.com "};
Intent. putExtra (Intent. EXTRA_EMAIL, tos );
Intent. putExtra (Intent. EXTRA_CC, ccs );
Intent. putExtra (Intent. EXTRA_BCC, bccs );
Intent. putExtra (Intent. EXTRA_TEXT, "body ");
Intent. putExtra (Intent. EXTRA_SUBJECT, "subject ");

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 ");
StartActivity (intent );

It is very simple. There are recipients, CC users, and BCC in the mail. That is, pass
Intent. EXTRA_EMAIL,
Intent. EXTRA_CC,
Intent. EXTRA_BCC
To set putExtra, and send a single attachment, use Intent. EXTRA_STREAM to set the URL Uri of the attachment.

3. Use SEND_MULTIPLE to send multiple attachments
[Java]Copy codeThe Code is as follows: 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 ");

ArrayList <uri> imageUris = new ArrayList <uri> ();
ImageUris. add (Uri. parse ("file: // mnt/sdcard/a.jpg "));
ImageUris. add (Uri. parse ("file: // mnt/sdcard/B .jpg "));
Intent. putParcelableArrayListExtra (Intent. EXTRA_STREAM, imageUris );
Intent. setType ("image /*");
Intent. setType ("message/rfc882 ");
Intent. createChooser (intent, "Choose Email Client ");
StartActivity (intent );

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

ArrayList <uri> imageUris = new ArrayList <uri> ();
ImageUris. add (Uri. parse ("file: // mnt/sdcard/a.jpg "));
ImageUris. add (Uri. parse ("file: // mnt/sdcard/B .jpg "));
Intent. putParcelableArrayListExtra (Intent. EXTRA_STREAM, imageUris );
Intent. setType ("image /*");
Intent. setType ("message/rfc882 ");
Intent. createChooser (intent, "Choose Email Client ");
StartActivity (intent );

When sending multiple attachments, you can use putParcelableArrayListExtra to set the Uri List of multiple attachments. In fact, it is quite simple.

Related Article

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.