1.pom.xml文件
org.springframework.boot spring-boot-starter-mail
2.application.properties配置
#发送邮件的配置
#用那个邮箱发送邮件 spring.mail.host=smtp.163.com #spring.mail.port=465 spring.mail.username=邮箱账号
spring.mail.password=邮箱密码 spring.mail.default-encoding=utf-8 spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true
3.实体类中
@Autowired private JavaMailSender sender; @Value("${spring.mail.username}") private String from;//邮箱名字
//邮箱 @RequestMapping("selectEmail") @ResponseBody public String selectEmail(){ System.out.println("进入"); SimpleMailMessage s=new SimpleMailMessage(); s.setFrom(from); s.setTo("123456@qq.com");//发送到那个邮箱账号 s.setSubject("标题"); s.setText("经过严格的筛选,您被确定为候选人,欢迎您来面试!"); sender.send(s); return "ok"; }
当前文章:SpringBoot,发送到邮箱
网页路径:https://www.cdcxhl.com/article36/chscsg.html
成都网站建设公司_创新互联,为您提供网站营销、用户体验、微信公众号、云服务器、网站制作、外贸建站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联