Python-从Outlook电子邮件中下载附件

时间:2020-05-03 15:39:02

标签: python outlook download attachment

我试图将所有收到的电子邮件中的附件下载到我的特定Outlook文件夹中,并将预定义的对象文本下载到一个文件夹中。

我尝试使用以下脚本,但是什么也没发生。

有人可以帮我吗?

import os
import win32com.client
import datetime
from datetime import datetime, timedelta
day = datetime.today()
d = datetime.today() - timedelta(days=4)
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders.Item("EmailAddress")
inbox = folder.Folders.Item("Inbox")
catalog = inbox.Folders.Item("FolderName")
messages  = catalog.Items
def saveattachemnts(subject):
for message in messages:
   if message.Subject == "StandardObjectText" and message.Unread and message.Senton.date() > d:
       attachments = message.Attachments
       attachment = attachments.Item(1)
       for attachment in message.Attachments:
         attachment.SaveAsFile(r"FolderPath")
         if message.Subject == subject and message.Unread:
                  message.Unread = False
         break

0 个答案:

没有答案
相关问题