我正在尝试在python mail中发送熊猫表。我试图但无法获得结果。还将熊猫数据框转换为html 这是我的代码。 请帮助
代码
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import pandas as pd
def sendMail(ID,NAME,MARKS):
dict = {'ID': ID, 'NAME':NAME, 'MARKS': MARKS}
da = pd.DataFrame(dict)
df=da.to_html()
try:
email = "EMAIL@gmail.COM"
password = 'PASSWORD'
send_to_email =["EMAIL@gmail.COM",]
subject = 'Critical Incident'
messageHTML = '{df}'
messagePlain = 'marks of your class'
print(messageHTML)
msg = MIMEMultipart('alternative')
msg['From'] = email
msg['To'] = ', '.join(send_to_email)
msg['Subject'] = subject
msg.attach(MIMEText(messagePlain, 'plain'))
msg.attach(MIMEText(messageHTML, 'html'))
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to_email, text)
server.quit()
答案 0 :(得分:0)
我找到了答案
df=da.to_html()
ds=str(df)
messageHTML = 'marks'+ds