顺序处理 Outlook 规则
我使用 Outlook 规则通过 VBA 宏处理传入邮件。 在 VBA 中,会触发各种操作来处理传入邮件的附件。
问题是,有时有一堆电子邮件需要处理。 我似乎找不到一种方法来一一触发。 如果有堆栈,我想在处理下一封邮件之前等待几秒钟。 在宏中添加 sleep 方法似乎没有效果。该规则似乎不会等待上一条消息完成。
我的方法是这样的:
有没有办法实现这种行为?
Private Sub ProcessMail(ByVal Item As Object)
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
If TypeOf Item Is Outlook.MailItem Then
Dim Msg As Outlook.MailItem
DoProcessingMethod
End If
End If
End Sub
在方法中放置等待或睡眠不会导致它被一一处理。
I use a outlook rule to process incoming mail via a VBA macro.
in the vba various actions are triggerd to process attachments of the incoming mail.
The problem is, there somethimes is a stack of e-mails that need to be processed.
I cant seem to find a way how to trigger the one by one.
I want to wait a few seconds before processing the next mail, if there is a stack.
Putting a sleep method in the macro doesnt seem to have effect. the rule doesnt seem to wait for the previous message to be done.
My method i something like:
Is there a way to accomplish this behaviour?
Private Sub ProcessMail(ByVal Item As Object)
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
If TypeOf Item Is Outlook.MailItem Then
Dim Msg As Outlook.MailItem
DoProcessingMethod
End If
End If
End Sub
Putting a wait or sleep in the method doesnt cause it to be processed one by one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GD Arnold,
您确实可以按照 @Brett 的回答使用
ItemAdd
选项。我使用类似的过程自动上传收到的数据(作为电子邮件中的附件)并将其上传到 MySQL 数据库。该操作由 ItemAdd 方法触发,并逐一检查邮件。
简化说明:
在名为“EventClassModule”的 VBA 代码中添加一个类
在您的类中,键入
在您的 ThisOutlookSession 中创建一个注册 event_handler 的子程序:
在您的 ThisOutlookSession 中创建一个处理 ItemAdd 事件的子程序,如下所示:
这些步骤应该为您提供当新邮件到达时触发的子程序。
然后你可以调用一个函数/子函数,如下所示。
下面的子程序基于可选的
ruleSet
变量运行所有规则,它根据规则集检查rule.Name
以及ruleSet
字符串是否存在于rule.Name
然后它执行一些代码。通过这种方式,您可以拥有多个规则,并且仅根据它们所属的“规则集”执行其中一些规则。您可以通过更改它们的名称来定义它。它是 Outlook 中“运行规则”选项的改进。
其中一些代码来自此处:设置 VBA 读取个人收件箱
GD Arnold,
You could indeed use the
ItemAdd
option as per @Brett's answer.I use a similar process to automatically upload received data (as attachment in an email) and upload this to a MySQL database. The action is triggered by the ItemAdd method and mails are checked one-by-one.
Simplified instructions:
Add a Class to your VBA code named "EventClassModule"
In your class, type
In your ThisOutlookSession make a sub that registers the event_handler:
In your ThisOutlookSession make a sub that handles the ItemAdd event as below:
These steps should provide you with a sub that is triggered when a new mail arrives.
You could then call a function/sub like below.
The below sub runs all rules based on an optional
ruleSet
variable, it checks therule.Name
against the ruleSet and if theruleSet
string exists in therule.Name
then it executes some code. This way you can have multiple rules and only execute some of them based on which 'ruleSet' they are part of. You can define that by altering their name.It's a refinement of the 'Run Rules' option in Outlook.
Some of this code came frome here: Setting VBA to read personal inbox
我遇到过类似的问题。就我而言,我的工具会定期运行,每次我只需捕获新电子邮件。现在新电子邮件可能是一封或多封。我找到的解决方案如下所示。
每次该工具都会运行。它将捕获新电子邮件并仅标记一个简单的“,”或“|”您在主题末尾选择的任何内容都不会被人注意到。现在,下次该工具运行时,它会检查一两天收到的电子邮件(根据您的要求)是否有这些标记。
如果电子邮件通信是一种方式,则此解决方案有效。如果我们使用这些电子邮件作为连锁电子邮件,那么它们是另一种解决方案。
在这里,您必须保存上次运行中捕获的电子邮件的最大时间。现在,每次运行时,您只需运行一整天,并放置一个 if 语句,该语句应该大于上次捕获的时间。
现在要存储您可能需要创建文件夹和电子邮件的最长时间。该电子邮件可以帮助您存储每次运行发生的时间
item.subject = maxtime
项目.保存
I have come across a similar problem. In my case my tool would run at regular time interval and each time I had to capture new emails only. Now new emails could be one or multiple. the solution I found was as given below.
Each time the tool would run. it will capture the new emails and just mark a simple ',' or '|' anything of your choice at the end of the subject in such a way that no one will notice. Now next time when the tool runs it checks if the emails received for the entire day or two (based on your requirements) has those markers or not.
This solution works if the email communication is one way. If we use these email for chain emails then their is another solution.
Here you will have to save the time max time of emails captured in the last run. Now each time you run you just have to run it for the entire day and put an if statement that is should be greater then time last captured.
Now to store the max time you might need to create a folder and an email. The email can help you to store the each time the run happens
item.subject = maxtime
item.save