QQ邮箱配置
设置->账户->开启服务:POP3/SMTP服务(此时需要手机发信息获取对应授权码用于登录)->保存更改。
java配置
1.导入jar包
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.7</version>
</dependency>
2.简单程序Demo
@Test
public void emailTest(){
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setUsername("自己的邮箱@qq.com");
mailSender.setPassword("邮箱配置返回的授权码");
mailSender.setHost("smtp.qq.com");
mailSender.setPort(25);
mailSender.setProtocol("smtp");
SimpleMailMessage msg = new SimpleMailMessage();
msg.setFrom("自己的邮箱@qq.com");
msg.setSubject("主题");
msg.setText("你好。。。。。。。。。。。。。。");
msg.setTo("需要发送的邮箱@qq.com");
try{
mailSender.send(msg);
}
catch (MailException ex) {
// simply log it and go on...
System.err.println(ex.getMessage());
}
}
3.当然可以添加抄送人及附件和漂亮的邮件,更多内容可以参考:https://docs.spring.io/spring-framework/docs/current/reference/html/integration.html#mail