因此,我對python比較陌生,我試圖用附件發送電子郵件。我使用StackOverflow上這裏所描述的指南:How to send email attachments with PythonPython爲電子郵件附件名稱添加轉義字符
我用下面的代碼添加文件...
for f in glob.glob('./*/*'):
path = f.split('/')
with open(f, "rb") as fil:
msg.attach(MIMEApplication(
fil.read(),
Content_Disposition = 'attachment; filename="' + path[-1] + '"'
))
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(emailFrom, emailTo, msg.as_string())
server.quit()
當我收到的電子郵件,附件都被稱爲「NONAME」 。如果我在Gmail中打開原始電子郵件,則會顯示如下附件:
Content-Type: application/octet-stream; Content-Disposition="attachment;
filename=\"Daily Report.txt\""
爲什麼名稱未正確通過?
丟失'filename ='中的雙引號。 – akshay
已經嘗試過了......不幸的是,它不起作用。 –
'msg'的類型是什麼? –