Android development of the implementation of the Send mail function (source code sharing)

Source: Internet
Author: User
Tags how to send mail

Android Development may encounter how to send mail trouble, before I also checked the relevant documents, Bo Friends also shared a lot of ways to send mail, a total of 3 kinds of put, I carefully read the next, found that some talk too complicated with trouble, not clear, I'm here today to share what I think is the best way to solve this problem, using the Andorid-mail jar package. First of all, we need to download the following four files first

Then, on the Android platform to send mail, must first check the status of the network, network status is available to send mail success AH (do not go to obtain network information need to add the appropriate permissions in the Androidmanifest.xml file. <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>)

The next step is even easier to read the code comments directly, we can solve the need to send mail!

    Network connection-related operations are done in a sub-thread, of course, you can also operate the service services class SendMessage extends Thread {@Overridepublic void Run () {//TODO Auto-generated method Stubsuper.run (); try {//Create Htmlemail class Htmlemail email = new Htmlemail ();//fill in the message host, I am using 163email.sethostname ("smtp.163.com"), Email.settls (True), Email.setssl (TRUE);//Set character encoding format, Prevent Chinese garbled email.setcharset ("GBK");//Set the recipient's mailbox Email.addto ("[email protected]");//Set the sender's mailbox Email.setfrom ("[Email Protected]///fill in the sender's username and password email.setauthentication ("123", "123");//fill in the subject of the message email.setsubject ("Hello");// Fill in the Message content email.setmsg (S1 + "\ n" + s2);//Send mail Email.send ();} catch (Emailexception e) {//TODO auto-generated catch blocklog.i ("TAG", "---------------->" +e.getmessage ());}}}

Better than the completion of the Android Send mail function, you can also study the other two ways to send mail. Share the shared address of the jar package that you have just described here.

    Mail's jar package for Android to send 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.