【发布时间】:2015-06-20 12:05:36
【问题描述】:
我在 Windows 8.1 上使用yagmail-0.3.78 和 Python 3.3。我可以让 yagmail 从我的控制台发送电子邮件,但附件不起作用。
yagmail.Connect('myemail@gmail.com','password').send('someguy@gmail.com', 'Test', 'This is a test', 'c:\\users\\lenovo\\appdata\\local\\temp\\mydoc.docx')
这会在控制台中返回一个没有错误的空字典。电子邮件显示正确的主题和正文,但没有附件。起初我以为我的防病毒软件可能正在删除附件,但防病毒日志中没有任何内容表明它是。
附言显然没有 yagmail 的标签,我也没有创建它的代表。
Edit-1:一些进展(?)
contents = ['This is a test', 'c:\\users\\lenovo\\appdata\\local\\temp\\mydoc.docx']
yagmail.Connect('myemail@gmail.com','password').send('someguy@gmail.com', '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)
Edit-2:感谢 PascalvKooten,请参阅下面的答案。只是语法上的注释...
yagmail.SMTP('mymail@gmail.com','password').send('someguy@gmail.com','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('mymail@gmail.com','password').send('someguy@gmail.com','Test1.2',contents)
【问题讨论】:
-
713 到 715 位置有哪些字符?尝试更改 mydoc.docx 的内容。
-
我可能误读了代码,但它在我看来就像yagmail doesn't support attachments。
-
@SamuelTaylor 我同意附件部分似乎没有做任何事情和/或被注释掉。这有点可惜,也与 ReadMe 文件背道而驰,其中有一个附加 mp3 和 png 的示例。
-
@PascalvKooten 你能确认一下吗?谢谢。
-
啊,我想你有旧版本,用 pip install - U yagmail 升级。 (或 pip3)。请注意,您必须使用 yagmail.SMTP 而不是 yagmail.Connect。
标签: python python-3.x yagmail