我有一个将文件发送给不同供应商的脚本。所以内容部分每次迭代都会改变。它可以完美地发送一个附件,但是当我在内容部分(并且我也尝试过)中添加另一条路径时,它仍然只发送一个附件。
此外,一个奇怪的部分是它只发送新文件,而不是我已经发送了一段时间的那个正在工作的文件。
我尝试将多个附件添加到内容部分:
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])