python - Yagmail脚本不发送多个附件
问题描述
我有一个将文件发送给不同供应商的脚本。所以内容部分每次迭代都会改变。它可以完美地发送一个附件,但是当我在内容部分(并且我也尝试过)中添加另一条路径时,它仍然只发送一个附件。
此外,一个奇怪的部分是它只发送新文件,而不是我已经发送了一段时间的那个正在工作的文件。
我尝试将多个附件添加到内容部分:
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])
解决方案
推荐阅读
- javascript - 制作一个 HTML 元素数组
- r - 使用 expand.grid/crossing() 查找单个值和向量的组合,而不用元素分隔向量?
- c# - Xamarin.Android 中不接受 PKCS12 证书密码提示
- javascript - 使用 AJAX 将 .NET 对象传递给方法
- ios - 试图在 ViewController 中显示字典值
- c# - LUCENE.NET-如何修复在 C# 中生成的查询(更多的 4 个子句“OR”和多字段)
- javascript - 为什么动态创建的 IFRAME 会导致在 Firefox 中激活页面“停止”按钮?
- java - Android:滚动时 ScrollView 不清理背景
- html - 在父项下方水平居中工具提示而不设置静态宽度
- string - 是否可以针对反引号键入断言?