gpt4 book ai didi

python - 在电子邮件中发送多个 HTML 表

转载 作者:行者123 更新时间:2023-11-30 23:13:09 26 4
gpt4 key购买 nike

我有来自三个 .html 文件的 3 个 HTML 表,我需要使用 Python 依次通过电子邮件发送这些表。

目前仅附加 1 张 table 。如何附加所有 3 个?

#!/usr/bin/python
import time
import os,sys
from os import path
import re
import sys, ast
import subprocess
# Import smtplib for the actual sending function

from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from subprocess import Popen, PIPE
msg = MIMEMultipart('alternative')
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.

html = open('/root/madhu_test/bpstest/results/outnss.html')
htmla = open('/root/madhu_test/bpstest/results/outs2c.html')
htmlb = open('/root/madhu_test/bpstest/results/outrecommended.html')
html = html.read()
htmla = htmla.read()
htmlb = htmlb.read()

part2 = MIMEText(html, 'html')
part3 = MIMEText(htmla, 'html')
part4 = MIMEText(htmlb, 'html')


msg.attach(part2)
msg.attach(part3)
msg.attach(part4)


msg["From"] = "sauravb@juniper.net"
msg["To"] = "sauravb@juniper.net"
msg["Subject"] = "Sanity performance report"
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(msg.as_string())

最佳答案

我也有同样的要求。我使用了一个名为“report”的变量,其中包含所有 html 代码。所以我不断添加任意数量的表来报告变量

report = ""
report += table1data
report += "<br><br>"
report += table2data
.
.

最后将此变量附加为电子邮件文本。

这对我有用。

关于python - 在电子邮件中发送多个 HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29477683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com