0

我正在尝试使用 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")

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

4

1 回答 1

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有关更多信息,请参阅此内容。

于 2020-05-28T12:51:40.600 回答