The example of this article tells the method for Java to implement SMTP -based emails. Share it for everyone for your reference. The specific implementation method is as follows:
Import java.util.date; Import java.util.properties; Import javax.mail.authenticator; Import javax.mail.Message; the import; Import javax.mail.Session; Import javax.mail.transport; Import; javax.mail.internet.internetAddress; Import javax.mail.internet.mimeMessage; Import Org.apache.logger; Public Class Mailutil { static loger logger = logger.getLogger (mailutil.class); /*** Send mail * * @param SMTP * SMTP server * @param user * Username * @param password * Password * @param Subject * Title * @param Content * @param from * @param to * * Receive Human mailbox*/ Public Static Void Send (String SMTP, Final String User, FINAL String Password, String Subject, String Content, String TO) rops = new property (); props.put ("mail. smtp.host ", smtp); props.put (" Mail.smtp.auth "," true "); session ssn = session.getInstance (props, new authenticator () {@Override Protected Pas swordAuthentication getpasswordAuthentication () {Return New PasswordAuthentication (user, password);}}); ; ); // Set the sender Internetaddress toaddress = New Internetaddress (to); // The email address of the recipient message.addrecipient (message.Recipienttype.to, Toaddress); // Set the recipient Message.setSubject (subject) ; // Set the title Message.setText (Content); // Set content message.setSetDate (new date ()); // Set the sending time transport transport = ssn.gettransport ("SMTP"); Ect (SMTP, User, password); Transport.SendMessage (Message, Message .GetRcipients (MESSAGE.RCIPIENTTYPE.TO)); // Transport.Send (Message); e (); logger.info ("Mail sending success");} cach (Exception E) {logger.warn ("Email Send Fail", E);}}}It is hoped that this article is helpful to everyone's Java program design.