小编Ana*_*ina的帖子

添加通过 Python 通过电子邮件发送的表格的边框

目前,我使用此解决方案Send table as an email body (not attachment ) 在 Python中通过 Python 在电子邮件中发送表格:

import smtplib
from smtplib import SMTPException
import csv
from tabulate import tabulate

text = """
Hello, Friend.

Here is your data:

{table}

Regards,

Me"""

html = """
<html><body><p>Hello, Friend.</p>
<p>Here is your data:</p>
{table}
<p>Regards,</p>
<p>Me</p>
</body></html>
"""

with open('result.csv') as input_file:
    reader = csv.reader(input_file)
    data = list(reader)

text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))

message = MIMEMultipart(
    "alternative", None, [MIMEText(text), MIMEText(html,'html')]) …
Run Code Online (Sandbox Code Playgroud)

html python email smtplib

2
推荐指数
1
解决办法
9804
查看次数

标签 统计

email ×1

html ×1

python ×1

smtplib ×1