JAVA uses QQ mailbox to send mail

Source: Internet
Author: User

Introduce a rack package:

The code is as follows:

Private Static FinalString qq_email_host= "smtp.qq.com";//QQ SMTP Server address    Private Static FinalString qq_email_port= "587";//QQ SMTP Server port (465 This port has a problem)    Private Static FinalString qq_email_from= "[EMAIL protected]";//QQ Sender Email    Private Static FinalString qq_email_password_code= "xxxxxxxxxxxxxxx";//QQ 16-digit Authorization Code         Public Static  voidSendqqemail (String to_address, string title, string content)throwsunsupportedencodingexception, messagingexception {//create properties class to record some attributes of a mailboxProperties props =NewProperties (); //indicates that SMTP sends a message and must be authenticatedProps.put ("Mail.smtp.auth", "true"); //fill out the SMTP server hereProps.put ("Mail.smtp.host", Qq_email_host); //Port number, QQ mailbox gave two ports, 465 this port with a problem, with this 587Props.put ("Mail.smtp.port", Qq_email_port); //fill in your sender account hereProps.put ("Mail.user", Qq_email_from); //The password here is the previously mentioned 16-bit STMP password (authorization code)Props.put ("Mail.password", Qq_email_password_code); //Building authorization information for SMTP authenticationAuthenticator Authenticator =NewAuthenticator () {protectedpasswordauthentication getpasswordauthentication () {String userName= Props.getproperty ("Mail.user"); String Password= Props.getproperty ("Mail.password"); return Newpasswordauthentication (userName, password);        }        }; //Create a mail session using environment properties and authorization informationSession mailsession =session.getinstance (props, authenticator); //Create a mail messageMimeMessage message =Newmimemessage (mailsession); //Set Senderinternetaddress form =NewInternetAddress (Props.getproperty ("Mail.user"));        Message.setfrom (form); //set the recipient's mailbox: The recipient's mailbox is not limited to QQ mailbox, can also be 163 mailbox ...InternetAddress to =Newinternetaddress (to_address);        Message.setrecipient (Message.RecipientType.TO, to); //set the message headerMessage.setsubject (title); //set the content body of a messageMessage.setcontent (Content, "Text/html;charset=utf-8"); //And then, of course, send mail.transport.send (message); }

JAVA uses QQ mailbox 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.