python+Html 发送带表格的邮件

    def create_pcn_html(self, pcn, pcn_classfy):
        """
        @author: 
        @date: 2023-07-28 15:57:01
        @description: 设置邮件发送HTML模板,拼接html,设计拼接邮件内容
        """
        html = """
                    <!DOCTYPE html>
                    <html lang="en">
                    <body>
                        <div style="margin-bottom:16px;">
                            <div><b><font size="3"> Hi, all,该邮件为XXXXX!</font></b></div>
                            <div>
                                <p class="p1" style="text-indent:2em;"> 1.XXXX:<font color="red" size="3">{}</font> </p> 
                                <p class="p1" style="text-indent:2em;"> 2. XXXX: 
                                    <font color="blue" size="3">{}</font> 
                                    XXXXXXXXXXX。 </p> 
                                <p class="p1" style="text-indent:2em;"> 3. XXXXX:{} </p> 
                                <p class="p1" style="text-indent:2em;"> 4. XXXXX:{} </p> 
                                <p class="p1" style="text-indent:2em;"> 5. XXXXX:{} </p> 
                             </div>
                            <table width="100%" height="10px" align="left" border="1" cellpadding="10px" cellspacing="0">
                                <tr>
                                    <th>ID</th><th>表头1</th>
                                    <th>表头2</th><th>表头3</th>
                                    <th>表头4</th><th>表头5</th>
                                    <th>表头6</th><th>表头7</th>
                                </tr>
                                {}  

                            </table>
                        </div>
                    </body>
                     </html>
                    """
        table_info = self.get_table_info(pcn_classfy)
        pcn_html = html.format(pcn.ig_ec_type, pcn.ig_change, pcn.ig_mpn, pcn.ig_sqe_remark, pcn.ig_ce_remark,
                               '\n'.join(table_info))
        return pcn_html

    def get_table_info(self, pcn_classfy):
        text = """<tr><td align='center'>{}</td><td align='center'>{}</td><td align='center'>{}</td>
                                <td align='center'>{}</td><td align='center'>{}</td><td align='center'>{}</td>
                                <td align='center'>{}</td><td align='center'>{}</td>
                           </tr>"""

        table_info = []
        for id, record in enumerate(pcn_classfy):
            kv_replace_map = {
                "H": "<font color='red'>H(重点关注)</font>",
                "L": "<font color='blue'>L(一般关注)</font>",
                "N": "<font color='green'>N(无影响)</font>",
            }
            result = [kv_replace_map[i] if i in kv_replace_map else i for i in record]
            data = text.format(id + 1, result[0], result[1], result[2], result[3], result[4], result[5], result[6])
            table_info.append(data)
        return table_info

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值