SpringBoot发送邮箱

创建一个邮箱

曾都网站建设公司创新互联,曾都网站设计制作,有大型网站制作公司丰富经验。已为曾都成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的曾都做网站的公司定做!

在设置里开启IMAP/SMTP服务(这里是126网易邮箱)



创建一个application.properties用来做配置文件

#编码 spring.mail.default-encoding=UTF-8 spring.mail.host=smtp.126.com #密码 spring.mail.password=123456 #端口 spring.mail.port=25 #协议 spring.mail.protocol=smtp #邮箱号 spring.mail.username=tao_hg@126.com创建一个java类用来向邮箱发送邮件

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MailController { @Autowired private JavaMailSender jms;//借助这个类,我们便可以发邮件了 @GetMapping("/send") public String send(String message){ SimpleMailMessage ss=new SimpleMailMessage(); //发送邮箱 ss.setFrom("tao_hg@126.com"); //接收邮箱 ss.setTo("201883607@qq.com"); //标题 ss.setSubject("测试"); //内容 ss.setText("测试一下耍耍"); jms.send(ss); return "1"; } }启动

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Test { public static void main(String[] args) { SpringApplication.run(Test.class, args); } }


当前文章:SpringBoot发送邮箱
本文网址:http://ybzwz.com/article/cpcopi.html