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
python+Html 发送带表格的邮件
于 2023-10-18 09:58:38 首次发布