基于日期,发件人和主题行的带有MAPI python的Outlook下载附件

时间:2018-12-20 09:03:11

标签: python email outlook win32com

我是完全陌生的人,我试图根据日期,发件人的电子邮件地址和主题行使用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'

请帮助!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我有相同的错误消息,但发现这是我的语法。改变中 SentonSentOn清除了错误。

相关问题