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. )

 Public Boolean isnetworkconnected (context context) {ifnull==  Mconnectivitymanager.getactivenetworkinfo (); if NULL ) {return  mnetworkinfo.isavailable ();}} return false;

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, but can also be manipulated in service servicesclassSendMessage extends Thread {@Override Public voidrun () {//TODO auto-generated Method StubSuper.run (); Try {             //creating the Htmlemail classHtmlemail email =NewHtmlemail (); //The host of the message is filled out, and I'm using 163.Email.sethostname ("smtp.163.com"); Email.settls (true); Email.setssl (true); //set character encoding format to prevent Chinese garbled charactersEmail.setcharset ("GBK"); //set the recipient's mailboxEmail.addto ("[email protected]"); //Set the sender's mailboxEmail.setfrom ("[email protected]"); //fill in the sender's user name and passwordEmail.setauthentication ("123","123"); //fill in the message subjectEmail.setsubject ("Hello"); //fill in the email contentEmail.setmsg (S1 +"\ n"+S2); //Send mailEmail.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.

The Mail jar package required for Android to send messages

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

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.