Android Development javamail Send mail (user feedback)

Source: Internet
Author: User

Add a user feedback to the app small function, due to lazy server, so in the form of mail communication, like the following two ways:

1. Use other programs on your phone to complete mail delivery

2. Use JavaMail to send mail

This is a decisive use of javamail, as most of us do not use the Mail app on our phones.

Using JavaMail requires three jar packages, namely Additional.jar, Mail.jar and Activation.jar, which can be downloaded from Google: https://code.google.com/archive/p/ Javamail-android/downloads

I was unable to Google domain name, Baidu a lot, after the various   java Span class= "pun" > lang . noclassdeffounderror : javax . activation . datahandler error because there is a problem with the imported Activation.jar package, which is put on the download from Google:

http://download.csdn.net/detail/u012062785/9685867

Eclipse Import Jar Package Method:

1. At the root of the project, create a new folder Libs, and put the downloaded 3 jar packages into the folder

2. Select the item, Right-click->properties->java Build path->libraries, select Add External JARs, find 3 jar packages under the project Lib directory, complete the import

Next, go directly to the source

1  PackageCom.pngcui.testmail;2 3 Importjava.util.Properties;4 5 ImportJavax.mail.Message;6 Importjavax.mail.MessagingException;7 Importjavax.mail.PasswordAuthentication;8 Importjavax.mail.Session;9 ImportJavax.mail.Transport;Ten Importjavax.mail.internet.InternetAddress; One ImportJavax.mail.internet.MimeMessage; A  -  -  Public classMailSend { the      -     PrivateString Mailcontext; -      -      PublicMailSend (String context) { +          This. Mailcontext =context; -     } +      A      Public voidSendMail ()throwsmessagingexception{ atProperties props =NewProperties (); -         //use the SMTP proxy and use the NetEase 163 mailbox -Props.put ("Mail.smtp.host", "smtp.163.cn"); -         //Set up validation -Props.put ("Mail.smtp.auth", "true"); -Myauthenticator Myauth =NewMyauthenticator ("Sender mailbox @163.com", "Password"); inSession session =session.getinstance (Props,myauth); -         //turn on the debug switch toSession.setdebug (true); +MimeMessage message =NewMimeMessage (session); -InternetAddress fromaddress =NULL; the         //Sender e-mail address *Fromaddress =NewInternetAddress ("Sender Mailbox @163.com"); $ Message.setfrom (fromaddress);Panax Notoginseng          -InternetAddress toaddress =NewInternetAddress ("Recipient's email address"); the message.addrecipient (Message.RecipientType.TO, toaddress); +Message.setsubject ("Message title"); AMessage.settext (Mailcontext);//set up message content the         //Message.setfilename ("Mail Attachment"); +Message.savechanges ();//Storing information -          $          $Transport Transport =NULL; -Transport = Session.gettransport ("SMTP"); -Transport.connect ("smtp.163.com", "Sender mailbox @163.com", "Password"); the transport.sendmessage (Message, message.getallrecipients ()); -         Wuyi transport.close (); the     } -      Wu     classMyauthenticatorextendsJavax.mail.Authenticator { -         PrivateString struser;  About         PrivateString strpwd;  $        -          Publicmyauthenticator (string user, string password) { -              This. struser =user;  -              This. strpwd =password;  A         }   +        the @Override -         protectedpasswordauthentication getpasswordauthentication () { $             return Newpasswordauthentication (struser, strpwd);  the         }   the     } the}

Last Appendix a few of the questions that I encountered

1.Authentication authentication failed because your password or email address is wrong, 163 of the mailbox try not to use the new application, and this password is the client authorization password, not your mailbox login password!

2. com.sun.mail.smtp.smtpsendfailedexception:554 DT:SPM 163 SMTP4, encountered this problem is anti-spam = =, Do not appear in the message header or message text test or HelloWorld content, or NetEase will be considered spam, resulting in unable to send out. Unable to send the reason can refer to http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html

Finally call new MailSend ("message body"). SendMail (); You can send it out!!

Android Development javamail Send mail (user feedback)

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.