public class MailKit {
public static void sendMail(String mailTo, String title, String code) {
//发送者的邮箱
String from = Static.MAIL_FROM;
Properties props = System.getProperties();
//邮箱格式qq/163
props.setProperty("mail.smtp.host", "smtp.163.com");
props.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
message.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress(mailTo));
message.setSubject(title);
//短信内容
message.setContent("<h1>此邮件为官方激活邮件!请点击下面链接完成激活操作!" + code + "</h1>", "text/html;charset=UTF-8");
Transport transport = session.getTransport("smtp");
//发送人的邮箱类型、用户名、密码
transport.connect(Static.MAIL_HOST, Static.MAIL_USER, Static.MAIL_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
————————————————
版权声明:本文为CSDN博主「xinyugogo」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_38284251/article/details/81099679