2017-05-30 131 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

谢谢吉米!用你的答案编辑第一个问题 –

相关问题