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

推荐订阅源

腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
The Cloudflare Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
Jina AI
Jina AI
V
V2EX
罗磊的独立博客
V
Visual Studio Blog
A
About on SuperTechFans
IT之家
IT之家
P
Proofpoint News Feed
B
Blog
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Y
Y Combinator 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);

然后发送邮件