Android simple email sending (with attachments)

Source: Internet
Author: User

The project encountered a mail sending function, which found a lot of information on the Internet. I will not introduce them here. I just wrote out the solution I used (the simplest)


Intent email = new intent (Android. content. intent. action_send); // mail sending type: no attachment, plain text email. settype ("plain/text"); // mail recipient (array, can be multiple recipients) string [] emailreciver = new string [] {"123@qq.com ", "456@163.com"}; string emailtitle = "title"; string emailcontent = "content"; // set the Email Address Email. putextra (Android. content. intent. extra_email, emailreciver); // set the email subject email. putextra (Android. content. intent. extra_subject, emailtitle); // you can specify the email address of the sent content. putextra (Android. content. intent. extra_text, emailcontent); // call the system's email system startactivity (intent. createchooser (email, "select email sending software "));

The code is very simple. Copy the Code directly, and then modify the code (I tried it myself ). As I said, this is the simplest way. It mainly sends emails by calling the system's mail. Its advantage is simplicity and convenience. If you have installed the android client for QQ mailbox, Gmail mailbox, and 163 mailbox, the system will prompt you which one to choose when sending the email. If you have not installed the preceding email client, you can call the system's email client.


The following is a code that can send attachments. Of course, this is also the simplest method.


Intent email = new intent (Android. content. intent. action_send); // The attachment file = new file (environment. getexternalstoragedirectory (). getpath () + file. separator + "simplenote" + file. separator + "note. XML "); // mail sending type: email with attachments. settype ("application/octet-stream"); // mail recipient (array, which can be multiple recipients) string [] emailreciver = new string [] {"123@qq.com ", "456@163.com"}; string emailtitle = "title"; string emailcontent = "content"; // set the Email Address Email. putextra (Android. content. intent. extra_email, emailreciver); // set the email subject email. putextra (Android. content. intent. extra_subject, emailtitle); // you can specify the email address of the sent content. putextra (Android. content. intent. extra_text, emailcontent); // attachment email. putextra (intent. extra_stream, Uri. fromfile (File); // call the system's email system startactivity (intent. createchooser (email, "select email sending software "));

By comparing the two sections of code, you will understand.

 

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.