没有合适的资源?快使用搜索试试~ 我知道了~
SpringBoot JavaMailSender发送邮件功能
5星 · 超过95%的资源 6 下载量 136 浏览量
2020-08-26
02:45:16
上传
评论
收藏 35KB PDF 举报
温馨提示
试读
2页
主要为大家详细介绍了SpringBoot JavaMailSender发送邮件功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
资源推荐
资源详情
资源评论
SpringBoot JavaMailSender发送邮件功能发送邮件功能
主要为大家详细介绍了SpringBoot JavaMailSender发送邮件功能,具有一定的参考价值,感兴趣的小伙伴们可
以参考一下
本文实例为大家分享了SpringBoot JavaMailSender发送邮件的具体代码,供大家参考,具体内容如下
引入Maven依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
163邮箱邮箱
application.properties
#####163邮箱########
spring.mail.host=smtp.163.com
spring.mail.username=*****@163.com
#163邮箱密码
spring.mail.password=!@#$%^&*
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
运行类:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
public class My163MailTest {
@Autowired
private JavaMailSender javaMailSender;
@Value("${spring.mail.username}")
private String username;
@Test
public void testSendSimple() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(username);
message.setTo("*******@qq.com");
message.setSubject("标题:测试标题");
message.setText("测试内容部份");
javaMailSender.send(message);
}
}
QQ邮箱和163邮箱的区别是需要设置授权码而不是密码,具体操作参考: 地址
application.properties
######qq邮箱########
spring.mail.host=smtp.qq.com
spring.mail.username=******@qq.com
#QQ邮箱授权码
spring.mail.password=xuojxtkdojvzbhjj
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
运行类:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
weixin_38693657
- 粉丝: 0
- 资源: 926
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页