Yagmail脚本未发送多个附件

时间:2019-08-07 15:57:45

标签: python yagmail

我有一个脚本,可以将文件发送给许多不同的供应商。因此,内容部分每次迭代都会更改。它可以完美地发送一个附件,但是当我在内容部分中添加另一个路径(并且我也尝试过).send()部分时,它仍然仅发送一个附件。

另外,一个奇怪的部分是它只发送新文件,而不发送我已经工作了一段时间的文件。

我尝试将多个附件添加到内容部分:

contents=['Hi '+ vendor_info[vendor_count][0] +
'irrelevant text', attachment, instruction_doc]

*我已经尝试在.send()中使用它创建文件路径列表*

attachments = [attachment, instruction_doc]
yag.send(recipient,subject,contents,attachments)

在这两个示例中,当我收到测试电子邮件时,收到的唯一附件是说明文档*

还有更多代码可提供更好的理解:

#reads from config file where the folder of files is
#can be changed via gui menu
vendor_attach_directory = (parser.get(
        'VendorFile', 'File_Location') + "/")

instruction_doc="C:/Users/Ryan/Desktop/instructions.txt "

while vendor_count < num_vendors:
        recipient = vendor_info[vendor_count][1]
        subject = 'Open PO Report' + ' for ' + vendor_info[vendor_count][0]
        attachment = vendor_attach_directory +'testdoc.txt'
        attachments = [attachment,instruction_doc]


        if os.path.isfile(attachment) == True:
            pass
        else:
            vendor_no_attach.append(vendor_info[vendor_count][0])
            vendor_count += 1
            continue
        contents = ['Hi '+ vendor_info[vendor_count][0] +
                    'irrelevant text']
        try:
            yag.send(recipient, subject, contents, attachments)

        except yagmail.error.YagInvalidEmailAddress:          
            invalid_emails.append(vendor_info[vendor_count])

0 个答案:

没有答案