JavaMail sends an email for publishing. javamail sends an email.

Source: Internet
Author: User
Tags ssl connection

JavaMail sends an email for publishing. javamail sends an email.

Errors are always reported when sending emails in java. The error message is javax. mail. AuthenticationFailedException.

Unable to connect to the smtp server, the reason is stmp server is not authorized, for example, you use qq mail: 927xxxxx@qq.com you must authorize the current mailbox, the authorization steps Baidu is very simple, authorization is enabled when you need to send a text message.

Transport transport = mailSession. getTransport ("smtp"); transport. connect (smtpHost, "xxxxx@163.com", "password"); // The password is the authorization code transport. sendMessage (testMessage, testMessage. getAllRecipients (); transport. close ();

In this case, the error javax. mail. AuthenticationFailedException will not be reported.
I found another error while continuing the test.

javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)    at javax.mail.Service.connect(Service.java:295)    at javax.mail.Service.connect(Service.java:176)    at com.ab.itws.common.SendHtmlMail.sendMessage(SendHtmlMail.java:43)    at com.ab.itws.common.SendHtmlMail.main(SendHtmlMail.java:61)

 

Port problems discovered

// SMTP server port (the default port for non-SSL connection is 25, which can be left blank. If SSL connection is enabled, /// * You need to change the SMTP server port of the corresponding mailbox. For details, see the help of the corresponding mailbox service. // The SMTP (SLL) Port of the QQ mailbox is 465 or 587 ,*/
System. out. println ("processing ing mail session for:" + smtpHost );
Java. util. Properties props = new java. util. Properties ();
Props. setProperty ("mail. smtp. auth", "true"); // specifies whether SMTP verification is required.
Props. setProperty ("mail. smtp. host", smtpHost); // specifies the SMTP server
Props. put ("mail. transport. protocol", "smtp ");
Props. put ("mail. smtp. port", "587"); // SMTP port number
Session mailSession = Session. getDefaultInstance (props );
MailSession. setDebug (true); // whether the debug information is displayed on the console

After the port is changed, the problem is finally solved.
Email sent successfully

 

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.