首页 > 代码库 > 邮箱认证

邮箱认证

Spring整合javamail发送邮件

1.导入Javamail的依赖  

2.Spring整合javamail

3.在邮箱中将POP3/SMTP服务开启

4.使用JavaMailSenderImpl对象来发送邮件

 

 1 @Service
 2 public class EmailServiceImpl{
 3 
 4     @Autowired
 5     private JavaMailSender mailSender;
 6 
 7     //email 接收者  标题 内容
 8     public void sendEmail(String email,String title,String content){
 9     //创建一个邮件信息
10     MimeMessage mm = mailSender.createMimeMessage();
11 
12     MimeMessageHelper helper = new MimeMessageHelper(mm);
13     helper.setFrom("wenbowen520@qq.com");
14     helper.sertSubject("title");
15     helper.setText(content,true);
16     helper.setTo(email);
17 
18     mailSender.send(mm);
19     }
20 }

 

邮箱认证