Pandas DF作为电子邮件正文

时间:2017-07-26 18:15:57

标签: python email

filename = "test.html"
f = file(filename)
attachment = MIMEText(f.read(),'html')
msg.attach(attachment)

按上述方式尝试时,获取Name Error: name 'file' not defined。请帮助解决此错误。

2 个答案:

答案 0 :(得分:0)

由于没有函数file(),您必须稍微更改它,错误信息明确说明。

filename = "text.txt"
with open(filename,'r') as file:
    attachment = MIMEText(file.read())

答案 1 :(得分:0)

你可能想打开这个文件? :

filename = "test.html"
f = open(filename 'r')
attachment = MIMEText(f.read(),'html')
msg.attach(attachment)