检查发件人电子邮件地址 [英] Check for the senderEmailAddress

查看:35
本文介绍了检查发件人电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Outlook 框中的 VBA 中有一个侦听器,可以在收到来自特定电子邮件的邮件时执行操作.

问题是,如果我收到错误邮件(未送达的电子邮件),那么我的条件会在没有该属性的邮件上运行,因此我的方法会崩溃.

我也不知道主题是什么.

有没有人知道我是否可以测试该属性是否存在,或者是否还有其他属性我可以检查以确定我的发件人是否匹配?

非常感谢

Sub SetFlagIcon()将 mpfInbox 调暗为 Outlook.FolderDim obj As Outlook.MailItemDim i 作为整数设置 mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test")' 循环 InboxTest 文件夹中的所有项目对于 i = 1 到 mpfInbox.Items.Count如果 mpfInbox.Items(i).Class = olMail 那么设置 obj = mpfInbox.Items.Item(i)如果 obj.SenderEmailAddress = "someone@example.com" 然后'设置黄旗图标obj.FlagIcon = olYellowFlagIcon对象保存万一万一下一个结束子

解决方案

Dim obj as a generic Object - 有收件箱中 MailItem 以外的对象,也可以尝试使用 Items.Restrict 方法(展望)

选项显式子 SetFlagIcon()将 mpfInbox 调暗为 Outlook.FolderDim obj 作为对象将项目调暗为 Outlook.Items昏暗的我将过滤器调暗为字符串设置 mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder _(olFolderInbox).Folders("Temp")过滤器 = "[SenderEmailAddress] = 'someone@example.com'"设置项目 = mpfInbox.Items.Restrict(Filter)' 循环 InboxTest 文件夹中的所有项目对于 i = 1 To Items.CountIf Items(i).Class = olMail 那么设置 obj = Items(i)'设置黄旗图标obj.FlagIcon = olYellowFlagIcon对象保存万一下一个结束子

<小时><块引用>

Items.Restrict Method 将过滤器应用于 项目 集合,返回一个新集合,其中包含原始中与过滤器匹配的所有项目.

I have a listener in VBA on my outlook box to perform an action if a receive a mail from a specific email.

The problem is that if I get a error mail (non-delivery email) then my condition is run on a mail which doesn't have that property so my method crashes.

I don't know what the subject may be either.

Does anyone have an idea if I can test if the property exists or if there is another property I can check for to identify if my sender matches?

Many thanks in advance

Sub SetFlagIcon() 

 Dim mpfInbox As Outlook.Folder 

 Dim obj As Outlook.MailItem 

 Dim i As Integer 



 Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test") 

 ' Loop all items in the InboxTest Folder 

 For i = 1 To mpfInbox.Items.Count 

 If mpfInbox.Items(i).Class = olMail Then 

 Set obj = mpfInbox.Items.Item(i) 

 If obj.SenderEmailAddress = "someone@example.com" Then 

 'Set the yellow flag icon 

 obj.FlagIcon = olYellowFlagIcon 

 obj.Save 

 End If 

 End If 

 Next 

End Sub

解决方案

Dim obj as a generic Object - there are objects other than MailItem in your Inbox, also to improve your loop try using Items.Restrict Method (Outlook)

Option Explicit
Sub SetFlagIcon()
    Dim mpfInbox As Outlook.Folder
    Dim obj As Object
    Dim Items As Outlook.Items
    Dim i As Long
    Dim Filter As String

    Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder _
                                    (olFolderInbox).Folders("Temp")

    Filter = "[SenderEmailAddress] = 'someone@example.com'"

    Set Items = mpfInbox.Items.Restrict(Filter)

    ' Loop all items in the InboxTest Folder
    For i = 1 To Items.Count
        If Items(i).Class = olMail Then
            Set obj = Items(i)
            'Set the yellow flag icon
            obj.FlagIcon = olYellowFlagIcon
            obj.Save
        End If
    Next

End Sub


Items.Restrict Method Applies a filter to the Items collection, returning a new collection containing all of the items from the original that match the filter.

这篇关于检查发件人电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆