How to call system email to send emails in Android Development

Source: Internet
Author: User

We all know that calling otherProgramAlmost all intent is used for related processing. Therefore, 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]
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 the 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]
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 = 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]
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.