spring.mail.host=smtp.gmail.com spring.mail.port=587 # replace with your own gmail here spring.mail.username=xxx@gmail.com # replace with your own password here spring.mail.password=xxxxxxxxxxxxxxxxxx # replace with your own gmail here, the same with above spring.mail.from=xxx@gmail.com spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true
我这里用到这么多配置就可以了,然后,如果想要更加细致的配置信息,可以去找 springboot 的文档,以及,java 的文档,毕竟,springboot 也只是对原生的 java mail 进行一次再封装。
@Test voidsendSimpleMail() { Stringto="xxxxxxxxx@gmail.com"; // replace with your own email Stringsubject="spring mail test"; Stringcontent="This is an email from spring-mail, just a test."; emailUtilService.sendSimpleMail(to, subject, content); } }