簡體   English   中英

Outlook根據日期、發件人和主題行使用MAPI python下載附件

[英]Outlook download attachments with MAPI python based on date, sender and subject line

我是全新的,我正在嘗試根據日期、發件人的電子郵件地址和主題行使用 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'

請幫忙!

首先,這不是 MAPI——這是 Outlook 對象模型。 其次,您假設 Inbox 文件夾中只有MailItem對象 - 但您也可以有ReportItemMeetingItem等。首先確保您確實有一個MailItem對象 - 檢查Class屬性是否 == 43 ( olMailItem )

我有同樣的錯誤信息,但發現這是我的語法。 Senton更改為SentOn清除了錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM