简体   繁体   English

Outlook 2013 VBA 检查有效的传入电子邮件

[英]Outlook 2013 VBA to check for valid incoming emails

I wrote some VBA code for use in Outlook 2013. When I searched Google, I found a mention that I should always include a "class check" line near the top of my code.我编写了一些用于 Outlook 2013 的 VBA 代码。当我搜索 Google 时,我发现有人提到我应该始终在代码顶部附近包含“类检查”行。 Why?为什么?

I run this code as part of an Outlook "rule" and only when incoming emails are from a certain email address.我运行此代码作为 Outlook“规则”的一部分,并且仅当传入的电子邮件来自某个电子邮件地址时。

I don't want ANY emails skipped.我不想跳过任何电子邮件。

That "exit sub" line is skipping emails because CLASS is sometimes 43 and OlItemType is sometimes 0. “退出子”行跳过电子邮件,因为 CLASS 有时是 43,而 OlItemType 有时是 0。

What do those numbers mean and why am I getting them?这些数字是什么意思,为什么我会得到它们?

Sub AutoForwardIfFrom(objMail As Outlook.MailItem)
    ' Ensure we are working with email items only
    If (objMail.Class <> OlItemType.olMailItem) Then Exit Sub  

     ''''''''' My Code here

End Sub

I found a mention that I should always include a "class check" line near the top of my code.我发现有人提到我应该始终在代码顶部附近包含一个“类检查”行。 Why?为什么?

An incoming Outlook item can be represented by an meeting request item, not only mail items.传入的 Outlook 项目可以由会议请求项目表示,而不仅仅是邮件项目。 All Outlook items are classified by message classes.所有 Outlook 项目都按邮件类别分类。 The message class for an item is defined by its MessageClass property, and is used to identify the form that should be used to display the item.项目的消息类由其 MessageClass 属性定义,用于标识应用于显示项目的表单。

See Item Types and Message Classes which lists the message classes and their corresponding forms.请参阅 项目类型和消息类别,其中列出了消息类别及其相应的形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM