About Android sending mail

Source: Internet
Author: User

When Google published its Android phone platform, it emphasized the super-strong network support capability, so that it could send email whether through GPRS, 3G Telecom network or Wi-Fi network.
  
The Intent behavior used in sending messages is Android.content.Intent.ACTION_SEND. The mail delivery service, which is actually used on Android, is called the Gmail program, not the protocol that uses SMTP directly. Now introduce the list of features you need to use in this article:

• Verify that the user input is the correct mailbox format;
• Users can enter the mailbox manually, or long press the mailbox text box to jump to the contact person to find contacts, get the contact's mailbox, and then return;
• Send mail.

• Mail sender is not complex, mainly in the EditText, Button control construction, through the construction of a custom Intent (Android.content.Intent.ACTION_SEND) as an Activity to send email, In this intent, you must also use SetType () to determine the format of the email, use PutExtra () to place the mail in (Extra_email), the subject (Extra_subject), the message content (Extra_ TEXT) and other email fields (EXTRA_BCC, EXTRA_CC). The code is as follows:

Mybutton.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub

Intent mailintent=new Intent (Android.content.Intent.ACTION_SEND);

Mailintent.settype ("Plain/test");
Stremailreciver=new string[]{Myedittext.gettext (). toString ()};

Stremailcc=new String[]{myedittext2.gettext (). toString ()};

Stremailsubject=myedittext3.gettext (). toString ();

Stremailbody=myedittext4.gettext (). toString ();
Mailintent.putextra (Android.content.Intent.EXTRA_EMAIL, stremailreciver);

Mailintent.putextra (Android.content.Intent.EXTRA_CC, STREMAILCC);

Mailintent.putextra (Android.content.Intent.EXTRA_SUBJECT, stremailsubject);

Mailintent.putextra (Android.content.Intent.EXTRA_TEXT, stremailbody);

StartActivity (Intent.createchooser (Mailintent, Getresources (). getString (R.string.send)));


}
});

There are many ways to send email in Android, and this example is just one of them. Here are some other ways to share with you:

• Method Two
Uri uri=uri.parse ("mailto:[email protected]");
Intent mymailintent=new Intent (Intent.action_send,uri);
StartActivity (mymailintent);

• Method Three
Intent testintent=new Intent (intent.action_send);
String[] tos={"[email protected]"};
String[] ccs={"[email protected]"};
Testintent.putextra (Intent.extra_email, TOS);
Testintent.putextra (INTENT.EXTRA_CC, CCS);
Testintent.putextra (Intent.extra_text, "This is the content");
Testintent.putextra (Intent.extra_subject, "This is the title");
Testintent.settype ("message/rfc822");
StartActivity (Intent.createchooser (testintent, "send"));

• Method Four, upload the attachment, here to the SD card music file for example
Intent testn=new Intent (intent.action_send);
Testn.putextra (Intent.extra_subject, "title");
Testn.putextra (Intent.extra_stream, "File:///sdcard/music.mp3");
StartActivity (Intent.createchooser (TESTN, "send"));

     
• Use JavaMail. Here I will not introduce the implementation of the JavaMail method.

• Due to the current simulator is not built into the Gmail client terminal program, so send email program after sending data, the simulator will issue "No application can perform this action", I do not have an Android phone, it can not be tested, Please also have the Android phone friends can be tested, the results of feedback to me, thank you.

Author "Software Technology sharing"

About Android sending mail

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.