filename = "test.html"
f = file(filename)
attachment = MIMEText(f.read(),'html')
msg.attach(attachment)
按上述方式尝试时,获取Name Error: name 'file' not defined
。请帮助解决此错误。
答案 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)