Send a simple email to JavaMail.
It is very simple to send emails. There are a lot of emails on the Internet, but write your own records.
Package cn. jmail. test; import java. util. properties; import javax. mail. *; import javax. mail. internet. *; public class FirstMail {/*** simple email sending Method * @ param host IP address of the email sending server * @ param from sender address * @ param to recipient address * @ param subject topic * @ param text content * @ param senderUsername sender's account * @ param senderPassword sender's password * mail. smtp. whether auth requires authentication is generally required */public static void sendMail (String host, String from, String to, String subject, String text, final String senderUsername, final String senderPassword) {Properties props = System. getProperties (); props. put ("mail. smtp. host ", host); props. put ("mail. smtp. auth "," true "); Session session = Session. getDefaultInstance (props, new Authenticator () {@ Override public PasswordAuthentication getPasswordAuthentication () {return new PasswordAuthentication (senderUsername, senderPassword );}}); try {MimeMessage message = new MimeMessage (session); message. setFrom (new InternetAddress (from); message. addRecipient (Message. recipientType. TO, new InternetAddress (to); message. setSubject (subject); message. setText (text); Transport. send (message);} catch (AddressException e) {e. printStackTrace ();} catch (MessagingException e) {e. printStackTrace () ;}} public static void main (String [] args) {String host = "smtp.163.com"; String from = "xxxxxx@163.com"; String to = "xxxxxxxx@qq.com "; string subject = "Hello, this is a test email. "; String text =" Hello, LiLei. "; String senderUsername =" xxxxxx@163.com "; String senderPassword =" xxxxxx "; FirstMail. sendMail (host, from, to, subject, text, senderUsername, senderPassword );}}
Well, of course we won't miss the http://pan.baidu.com/s/1qW7LZvm.