我在Windows 8.1上使用yagmail -0.3.78和Python 3.3。我可以讓yagmail從我的控制檯發送電子郵件,但附件不起作用。Python yagmail附件不起作用
yagmail.Connect('[email protected]','password').send('[email protected]', 'Test', 'This is a test', 'c:\\users\\lenovo\\appdata\\local\\temp\\mydoc.docx')
這將在控制檯中返回一個沒有錯誤的空白字典。電子郵件顯示正確的主題和正文,但沒有附件。起初我以爲我的防病毒軟件可能會刪除附件,但防病毒日誌中沒有任何內容可以表明它的存在。
p.s.顯然沒有標籤爲yagmail,我沒有代表創建它。
編輯-1:(?)一些進展
contents = ['This is a test', 'c:\\users\\lenovo\\appdata\\local\\temp\\mydoc.docx']
yagmail.Connect('[email protected]','password').send('[email protected]', 'Test',contents)
...結果在下面的錯誤。
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
File "C:\Python33\lib\site-packages\yagmail-0.3.78-py3.3.egg\yagmail\yagmail.py", line 73, in send
return self._attempt_send(addresses['recipients'], msg.as_string())
File "C:\Python33\lib\site-packages\yagmail-0.3.78-py3.3.egg\yagmail\yagmail.py", line 79, in _attempt_send
result = self.smtp.sendmail(self.user, recipients, msg_string)
File "C:\Python33\lib\smtplib.py", line 749, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 713-715: ordinal not in range(128)
編輯-2:感謝PascalvKooten,見下面他的回答。只是注意語法...
yagmail.SMTP('[email protected]','password').send('[email protected]','Test1.2','This is a test','C:\\Users\\Lenovo\\AppData\\Local\\Temp\\mydoc.docx')
不適用於我。但是,下面的結構確實有效。
contents = ['This is a test', 'C:\\Users\\Lenovo\\AppData\\Local\\Temp\\mydoc.docx']
yagmail.SMTP('[email protected]','password').send('[email protected]','Test1.2',contents)
什麼字符在位置713到715?嘗試更改mydoc.docx的內容。 – gary
我可能會誤解代碼,但是在我看來,[yagmail不支持附件](https://github.com/kootenpv/yagmail/blob/master/yagmail/yagmail.py#L216)。 –
@SamuelTaylor我同意它看起來像附件部分沒有做任何事情和/或被註釋掉。這有點令人慚愧,並且還與附有mp3和png的示例的自述文件相反。 –