惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
罗磊的独立博客
The GitHub Blog
The GitHub Blog
L
LangChain Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
宝玉的分享
宝玉的分享
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
美团技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog

博客园 - Johnson_wang

对云服务器挂载cos桶 记录一次xxlJob升级版本导致的 xxl-job remoting error(Connection reset) 记一次NoClassDeffoundEror问题解决过程 nginx配置支持ws,并解决跨域 关于消费端接入dubbo,连接失败问题 RedisTemplate关于key出现前缀\xac\xed\x00\x05t\x00\x0f - Johnson_wang - 博客园 ES 单索引大表拆分 关于ES索引被聚合查询导致filedata堵塞 (pressure too high, (smooth) bulk request circuit break) elasticsearch报错FORBIDDEN/12/index read-only / allow delete spring Boot 相关问题以及修复(后续待补充) mybatis数据加解密处理方案 队列缓存区-db写入 synchronized的实现原理 Scheduler踩坑记录 关于RedisTemplate的map存储踩坑记录 关于HashMap的加载因子相关理解 Mybatis 分页插件PageHelper 遇坑 Linux 下 Mysql忘记密码重置 Eclipse MAT和jvisualvm分析内存溢出
发送HTML格式邮件
Johnson_wang · 2022-09-15 · via 博客园 - Johnson_wang

主要在于构建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);

然后发送邮件