SpringBoot中发送邮件服务

.转载:http://www.ityouknow.com/springboot/2017/05/06/spring-boot-mail.html

简单使用

1、pom 包配置

<dependency> 
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency> 

2、在 application.properties 中添加邮箱配置

spring.mail.host=smtp.qiye.163.com //邮箱服务器地址
[email protected] //用户名
spring.mail.password=xxyyooo    //密码
spring.mail.default-encoding=UTF-8

ps:补充,一般我们可以采用qq邮箱来进行测试

qq邮箱开通SMTP/POP3方法:https://jingyan.baidu.com/article/6d704a133a245f28db51caf5.html

4、编写 test 类进行测试

@Autowired
private JavaMailSender javaMailSender;

至此一个简单的文本发送就完成了。

加点料

但是在正常使用的过程中,我们通常在邮件中加入图片或者附件来丰富邮件的内容,下面讲介绍如何使用 Spring Boot 来发送丰富的邮件。

发送 html 格式邮件

发送带附件的邮件

发送带静态资源的邮件

邮件中的静态资源一般就是指图片。

扫描二维码关注公众号,回复: 7029569 查看本文章

添加多个图片可以使用多条 <img src='cid:" + contentId+ "' > 和 helper.addInline(contentId, res) 来实现。

到此所有的邮件发送服务已经完成了。

猜你喜欢

转载自www.cnblogs.com/cq-yangzhou/p/11356109.html