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.