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