发送HTML格式邮件
2022/9/15 23:17:22
本文主要是介绍发送HTML格式邮件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
主要在于构建HTML模板,新建类似模板:
<table border='0' th:each='data:${datas}' cellspacing='1' cellpadding='0' style='background:#DCDFE6; line-height: 30px;width: 900px; left:auto;'> <tr style="color: #000000;text-align: left;font-weight: bold;"> <td colspan='4'>任务名称:<span th:text='${data.taskName}'/></td> </tr> <tr style="text-align: left;"> <th style='background:#FFF;width: 80px; '>ID</th> <th style='background:#FFF;'>名称</th> <th style='background:#FFF;width: 60px;'>时间</th> <th style='background:#FFF;width: 60px;'>数量</th> </tr> <tr th:each='item:${data.list}' style="text-align: left;"> <td style="background: #FFF;width: 80px;" th:text='${item.id}'></td> <td style="background: #FFF;" th:text='${item.name}'></td> <td style="background: #FFF;width: 60px;" th:text='${item.time}'></td> <td style="background: #FFF;width: 60px;" th:text='${item.count}'></td> </tr> <br /> </table>
使用 thymeleaf 加载HTML,并赋值构造完整HTML页面。
引入插件:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.4.3</version> </dependency>
构建HTML
SpringTemplateEngine templateEngine = new SpringTemplateEngine(); Context context1 = new Context(); context1.setVariable("datas",list); String content = templateEngine.process(mailInfo.getMailContent(),context1);
然后发送邮件
这篇关于发送HTML格式邮件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-07金融企业区域集中库的设计构想和测试验证
- 2024-03-11前端CSS的工程化——掌握Sass这四大特性就够了
- 2024-02-21h5关联css样式(html怎么和css关联)-icode9专业技术文章分享
- 2024-02-07Firefox禁止远程字体加速网页加载及图标字体补充安装
- 2024-02-07一个菜鸡前端的3年总结-「2023」
- 2024-01-18最火前端Web组态软件(可视化)
- 2024-01-12程序员提效 x10 的必备开源“神器”
- 2024-01-11前端可以监控静态资源的时间吗-icode9专业技术文章分享
- 2024-01-11前端系列:ES6-ES12新语法
- 2024-01-03前端 Git 使用约定