您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Microsoft Outlook创建规则运行应用程序/脚本Python

Microsoft Outlook创建规则运行应用程序/脚本Python

如果您可以简单地从python完成所有操作,为什么要在Outlook中创建运行脚本的规则(如果收到电子邮件)。

使用Python监视所有传入电子邮件的外观,然后执行某些代码(如果可以接收到主题为%BLAHBLAH%的电子邮件)。这是一个例子:

import win32com.client
import pythoncom
import re

class Handler_Class(object):
    def OnNewMailEx(self, receivedItemsIDs):
        # RecrivedItemIDs is a collection of mail IDs separated by a ",".
        # You kNow, sometimes more than 1 mail is received at the same moment.
        for ID in receivedItemsIDs.split(","):
            mail = outlook.Session.GetItemFromID(ID)
            subject = mail.Subject
            try:
                # Taking all the "BLAHBLAH" which is enclosed by two "%". 
                command = re.search(r"%(.*?)%", subject).group(1)

                print command # Or whatever code you wish to execute.
            except:
                pass


outlook = win32com.client.DispatchWithEvents("Outlook.Application", Handler_Class)

#and then an infinit loop that waits from events.
pythoncom.PumpMessages()
python 2022/1/1 18:29:08 有193人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶