我正在尝试从Outlook收件箱中提取电子邮件附件,并将这些附件转储到文本文件中。到目前为止,这是我所做的:
import win32com.client
import os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6).Folders.Item("Special Folder")
messages = inbox.Items
message = messages.GetFirst()
#
get_path = os.getcwd() + '\\'
for m in messages:
attachments = message.Attachments
num_attach = len([x for x in attachments])
for x in range(1, num_attach + 1):
attachment = attachments.Item(x)
attachment.SaveASFile(os.path.join(get_path, attachment.FileName))
print(attachment)
message = messages.GetNext()
我面临的两个主要问题是:
运行这段代码时,它只会生成一堆@
符号,而不是下载附件;
我不知道如何将这些附件转储到文本文件中。
感谢您的帮助!谢谢。