2017-05-30 134 views
1

我正在嘗試創建一個腳本,以便每天將所有Outlook發送的郵件從上午8:00轉發到專用收件箱。Python - Win32Com - Outlook - 將今天發送的郵件轉發到收件箱

郵件必須保存在Outlook的已發送郵件文件夾中。

目前,我有今天的所有電子郵件,但劇本的前部不工作(我沒有任何錯誤消息)

編輯1:感謝吉米的限制主意!

import win32com.client as win32 

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI") 

outbox = outlook.GetDefaultFolder(6) 

messages = messages = outbox.Items.restrict("[SentOn] > '5/31/2017 08:00 AM'") 

for message in messages: 
    NewMsg = message.Forward() 
    NewMsg.To = "[email protected]" 

回答

0

已完成:對於那些有興趣,下面你可以找到解決辦法

import win32com.client as win32 

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI") 

outbox = outlook.GetDefaultFolder(5) 

messages = outbox.Items.restrict("[SentOn] > '5/30/2017 08:00 AM'") 

for message in messages: 
    NewMsg = message.Forward() 
    NewMsg.Body = message.Body 
    NewMsg.Subject = message.Subject 
    NewMsg.To = "[email protected]" 
    NewMsg.Send() 
1

對您正在使用的COM對象有一個限制方法,我以前使用過。 check this out

import win32com.client as win32 

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI") 

outbox = outlook.GetDefaultFolder(6) 

#try the restrict method! 
messages = outbox.Items.restrict("[SentOn] > '5/30/2017 12:00 AM'") 

for message in messages: 
    print message 
+0

謝謝吉米!用你的答案編輯第一個問題 –

相關問題