Outlook根据日期、发件人和主题下载带有MAPI python的附件

2024-04-23 12:03:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个全新的我试图下载附件使用MAPI的基础上日期,发件人的电子邮件地址和主题行。你知道吗

下面是我的代码:

import datetime 
from win32com.client import Dispatch
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder("6")
all_inbox = inbox.Items
folders = inbox.Folders
val_date = datetime.date.today().strftime("%d-%m-&y")
today = msg.Senton.date() = val_date
inboxtime = all_inbox and today
email_sender = 'Email input here'
sub_today = 'Subject line input here'
att_today = 'attachment name input here'

for msg in inboxtime:
    if msg.SenderEmailType == "EX":
       if msg.Sender.GetExchangeUser().PrimarySmtpAddress.find(email_sender) != -1
           break
else:
       if msg.SenderEmailAddress.find(email_sender) != -1 and msg.Senton.date() == val_date:
          break
For att in msg.Attachments:
if att.FileName == att_today:
   break
try:
    att.SaveAsFile('D:\\' + att.FileName)
    print(True)
except:
    print(False)

但是,它显示以下错误:

today= msg.Senton.date() == val_date
AttributeError: 'str' object has no attribute 'Senton'

请帮帮我!你知道吗


Tags: importinputtodaydateifhereemailmsg
1条回答
网友
1楼 · 发布于 2024-04-23 12:03:59

首先,这不是MAPI-这是Outlook对象模型。其次,假设收件箱文件夹中只有MailItem对象,但也可以有ReportItemMeetingItem等。首先确保确实有MailItem对象-检查Class属性==43(olMailItem

相关问题 更多 >