spring发送邮件
导包
javax.mail mail 1.4.1applicationContext.xml配置
true true注意:发送的邮箱要开启POP3/SMTP服务,生成授权码
controller代码
try {
//设定mail server
senderImpl.setHost(“smtp.qq.com”);
//建立邮件消息,发送简单邮件和html邮件的区别
MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,“UTF-8”);
//设置收件人,寄件人
messageHelper.setTo(email);
messageHelper.setFrom("xxxx@qq.com");
messageHelper.setSubject("密码找回");
//true 表示启动HTML格式的邮件
messageHelper.setText("<html><head></head><body><a href=''>点击链接找回密码</a></body></html>",true);
//发送邮件
senderImpl.send(mailMessage);
} catch (Exception e) {
e.printStackTrace();
}