【发布时间】:2018-04-23 23:02:21
【问题描述】:
for file in os.listdir(path):
try:
with open(file, 'r') as fp:
msg = MIMEBase('application', "octet-stream")
msg.set_payload(fp.read())
encoders.encode_base64(msg)
msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file))
outer.attach(msg)
except:
print("Unable to open one of the attachments. Error: ", sys.exc_info()[0])
raise
composed = outer.as_string()
我收到“FileNotFoundError: [Errno 2] No such file or directory”,但文件存在!可能是 os.listdir() 对象类型?
【问题讨论】:
标签: windows smtp python-3.6 mime