In the mobile Internet era, mobile mail is nothing new. We can use the built-in Gmail engine to send emails, or use SMTP to send emails, the following is a simple example to describe how to send an email, including sending a single email, sending a copy email, sending a BCC email, and sending an attachment. The Code is as follows:
Activity:
Package COM. home; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; public class sendemailactivity extends activity implements onclicklistener {private button sendbtn; private button sendtomanybtn; private button sendattachmentbtn; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); sendbtn = (button) findviewbyid (R. id. main_btn_send); sendtomanybtn = (button) findviewbyid (R. id. main_btn_send_listener); sendattachmentbtn = (button) findviewbyid (R. id. main_btn_send_attachment); sendbtn. setonclicklistener (this); sendtomanybtn. setonclicklistener (this); sendattachmentbtn. setonclicklistener (this) ;}@ overridepublic void onclick (view v) {If (V = sendbtn) {intent = new intent (intent. action_sendto); intent. setdata (URI. parse ("mailto: + 297890152@qq.com"); intent. putextra (intent. extra_subject, "this is the subject of the message sent unilaterally"); intent. putextra (intent. extra_text, "this is the content of the message sent unilaterally"); startactivity (intent);} If (V = sendtomanybtn) {intent = new intent (intent. action_sendto); intent. setdata (URI. parse ("mailto: 297890152@qq.com"); intent. putextra (intent. extra_email, new string [] {"313766045@qq.com", "980324510@qq.com"}); // CC intent. putextra (intent. extra_cc, new string [] {"981413230@qq.com"}); // BCC intent. putextra (intent. extra_bcc, new string [] {"1316106487@qq.com"}); intent. putextra (intent. extra_subject, "this is the subject of the email sent by multiple parties"); intent. putextra (intent. extra_text, "this is the mail content sent by multiple parties"); startactivity (intent);} If (V = sendattachmentbtn) {intent = new intent (intent. action_send); intent. putextra (intent. extra_email, new string [] {"297890152@qq.com"}); intent. putextra (intent. extra_subject, "this is the subject of the email containing the attachment"); intent. putextra (intent. extra_text, "this is the email content that contains attachments"); intent. putextra (intent. extra_stream, Uri. parse (""); intent. settype ("text/plain"); startactivity (intent );}}}
The layout file has only three buttons.