Here you can find the source of sendEmail(String subject, String text, String receiverEmail)
public static Boolean sendEmail(String subject, String text, String receiverEmail)
//package com.java2s; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; public class Main { private static final String smtpServerAddress = "smtp.126.com"; private static final String senderEmail = "panzhangbao@126.com"; private static final String senderAuthorizationCode = ""; public static Boolean sendEmail(String subject, String text, String receiverEmail) { Properties props = new Properties(); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", smtpServerAddress); Session session = Session.getInstance(props); session.setDebug(false);//from ww w .ja v a 2s .c om Message msg = new MimeMessage(session); try { msg.setSubject(subject); msg.setText(text); msg.setFrom(new InternetAddress(senderEmail)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(receiverEmail)); msg.saveChanges(); Transport transport = session.getTransport(); transport.connect(senderEmail, senderAuthorizationCode); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); return true; } catch (MessagingException e) { e.printStackTrace(); } return false; } }