Python yagmail 附件无效

Python yagmail attachment not working

我在 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')

这是一个 returns 控制台中没有错误的空字典。电子邮件显示正确的主题和正文,但没有附件。起初我以为我的防病毒软件可能正在删除附件,但防病毒日志中没有任何迹象表明它是。

p.s。显然没有 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)

作为yagmail包维护者的回答:见本期https://github.com/kootenpv/yagmail/issues/5

0.3.81版本应该可以解决

请更新为pip3 install -U yagmail

我从未测试过它可以在 windows 上运行,所以这是我唯一的不确定性。