【问题标题】:Sending pictures with yagmail doesn't work用yagmail发送图片不起作用
【发布时间】:2020-05-10 14:57:38
【问题描述】:

我正在尝试使用 yagmail 模块发送 png,但出现此错误:

代码如下:

import yagmail
import os

currentDirectory = os.getcwd()
path_fichier_screenshot2 = currentDirectory + "\\screenshot2.png"
print(path_fichier_screenshot2)

try:
    yag = yagmail.SMTP(user="myemail", password='pwd')
    contents = [yagmail.inline(path_fichier_screenshot2)]
    yag.send("target_email", "test", contents)
    print("Email sent successfully")
except:
    print("Error, email was not sent")

当我只发送文本时,它可以工作。 有什么线索吗?

【问题讨论】:

  • 您要将png 作为附件发送吗?
  • 您好,是的附件或更好,png 包含在电子邮件内容中。字数不多,内容太大,发不了邮件

标签: python python-3.x yagmail


【解决方案1】:

如果您想将图片作为附件发送,您可以这样做:

yag = yagmail.SMTP(user="myemail", password='pwd')
contents = "Hello , sending png as an attachment"
attachments = [path_fichier_screenshot2]

yag.send("target_email", "test", contents, attachments=attachments)

请参阅此doc 了解更多信息。

【讨论】:

  • 您好,我想我已经这样做了,但我遇到了同样的错误。我会再试一次。感谢回复
  • @AJT 如果答案有帮助,请考虑投票。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-09
相关资源
最近更新 更多