I want to produce two HTML tables using tabulate package, but I am only able to produce one table and send mail.
Is it possible to put more than one html table into a message sent with smtplib and email? Whenever I use attach() for more than one thing, it only adds the first.
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('input.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')]
)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…