Android development-mail sending function implementation (source code sharing), android mail sending

Source: Internet
Author: User

Android development-mail sending function implementation (source code sharing), android mail sending

Android development may encounter the issue of sending emails. I also checked the relevant documents before, and the bloggers also shared a lot of ways to send emails. There are three methods in total, I have read it carefully and found that some of my lectures are too complicated and difficult to understand. Today I will share my thoughts on the best way to solve this problem, use the Andorid-MAIL Jar package. First, download the following four files:

Then, when sending emails on the Android platform, you must first check the network status and make sure that the emails are successfully sent only when the network status is available (do not obtain Network Information in AndroidManifest. add the corresponding permissions to the xml file. <Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"/>)

public boolean isNetworkConnected(Context context) {if (context != null) {ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();if (mNetworkInfo != null) {return mNetworkInfo.isAvailable();}}return false;} 
The next step is simpler. You can directly view the code comments to solve our email sending needs!

// All operations related to network connections must be completed in the sub-Thread. Of course, you can also operate class sendMessage extends Thread {@ Overridepublic void run () in the Service () {// TODO Auto-generated method stubsuper. run (); try {// create HtmlEmail class HtmlEmail email = new HtmlEmail (); // enter the host information of the email. Here I use 163email. setHostName ("smtp.163.com"); email. setTLS (true); email. setSSL (true); // sets the character encoding format to prevent Chinese garbled emails. setCharset ("gbk"); // set the email address of the recipient. addTo ("123@qq.com"); // set the sender's email address. setFrom ("123@163.com"); // enter the sender's username and password email. setAuthentication ("123", "123"); // enter the email subject email. setSubject ("hello"); // enter the email content email. setMsg (s1 + "\ n" + s2); // send email. send ();} catch (EmailException e) {// TODO Auto-generated catch blockLog. I ("TAG", "---------------->" + e. getMessage ());}}}

Okay. Now we have completed the android mail sending function. You can also study the other two email sending methods. Here we will share the sharing address of the Jar package we just mentioned.

Jar package of the mail needed for android mail sending


How to Implement email Sending Technology in android Program Development

What functions do you want to implement? It means that you can simply send emails and directly call the system's email application.
 
Android code can be shared

Intent. ACTION_SEND, directly calling this Intent will pop up the share selection dialog box.

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.