Send emails in Android

Source: Internet
Author: User

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.

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.