【问题标题】:Python - Win32Com - Outlook - Forward today's sent items to an inboxPython - Win32Com - Outlook - 将今天发送的项目转发到收件箱
【发布时间】:2019-05-18 20:41:11
【问题描述】:

我正在尝试创建一个脚本,将每天早上 8:00 发送的所有 Outlook 发送的项目转发到专用收件箱。

邮件必须保存在 Outlook 的已发送邮件文件夹中。

目前我有今天所有的电子邮件,但脚本的转发部分不起作用(我没有任何错误消息)

编辑 1:感谢 Jimmy 的限制想法!

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 = "mail@mail.com" 

【问题讨论】:

    标签: python-2.7 loops outlook


    【解决方案1】:

    已完成:有兴趣的可以在下方找到解决方案

    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 = "mail@mail.com"
        NewMsg.Send()
    

    【讨论】:

    • 如何合并命令:[SentOn] 当前日期?
    【解决方案2】:

    在您正在使用的 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
    

    【讨论】:

    • 谢谢吉米!用你的答案编辑了第一个问题
    • 如何合并命令:[SentOn] 当前日期?
    • 嗨@jimmy,我怎样才能合并 [SentOn] 当前日期?
    猜你喜欢
    • 2018-10-27
    • 1970-01-01
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    • 2014-01-11
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多