每当我收到包含某个SUBJECT的附件的电子邮件时,它们会自动下载到我系统上的文件夹中。 这是我的代码:
import win32com.client
import os
current_path = os.getcwd()
outlook = win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
for m in messages:
if m.Subject == "TEST MAIL":
print("message body:", m.body)
attachment = messages.Attachments
for x in attachment:
x.SaveASFile(os.path.join(current_path, x.FileName))
以上代码无法正常工作并抛出异常:pywintypes.com_error:( - 2147221005,'无效的类字符串',无,无)
答案 0 :(得分:0)
替换
行 x.SaveASFile(os.path.join(current_path, "Test1.csv"))
与
x.SaveASFile(os.path.join(current_path, x.FileName))