我有三个.html文件中的3个HTML表格,我需要用一个在另一个下面的Python来发送电子邮件。在电子邮件中发送多个HTML表格
目前只有1个表正在附加。如何附加所有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"] = "[email protected]"
msg["To"] = "[email protected]"
msg["Subject"] = "Sanity performance report"
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(msg.as_string())
你想合并所有这些HTML文件并发送为一个单一的电子邮件? – Ajay
它是如何与当前的代码? –
是的。目前只添加第一个附件。 – bhasinusc