首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用VBA遍历电子邮件收件人并对照一系列域进行检查

使用VBA遍历电子邮件收件人并对照一系列域进行检查
EN

Stack Overflow用户
提问于 2019-02-22 05:41:21
回答 1查看 300关注 0票数 0

当我发送电子邮件(通过Outlook,所以我使用的是VBA)时,如果任何收件人地址的域不在域列表中,我希望在主题行中添加“zsecure”。

下面是我当前的代码:

代码语言:javascript
复制
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim addrRecips As Outlook.Recipients
    Dim addrRecip As Outlook.Recipient
    Dim arrDomain As Variant
    Dim pa As Outlook.PropertyAccessor
    Dim recipDomain As String
    Dim subjSecure As String

    Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    Set addrRecips = Item.Recipients

    ' Set up the array
    arrDomain = Array("domain1.com", "domain2.com", "domain3.com", "domain4.net")

    For Each addrRecip In addrRecips
        Set pa = addrRecip.PropertyAccessor

        ' Get the domain from the current recipient's email address
        recipDomain = Split(pa.GetProperty(PR_SMTP_ADDRESS), "@", 2, vbTextCompare)(1)
        Debug.Print recipDomain

        ' Check if the recipient's email domain is in the array of domains
        If IsInArray(recipDomain, arrDomain) = False Then
            Debug.Print "Recipient domain, " & recipDomain & ", is in array of domains"

            ' Current recipient's email domain is not in the list, so add " zsecure" to the subject
            subjSecure = Item.Subject & " zsecure"
            Item.Subject = subjSecure

            ' If any of the recipients' domains is not in the list, we can stop here and send the email
            Exit Sub
        End If
    Next

End Sub

当我尝试发送电子邮件时,"IsInArray“被高亮显示(选中),错误消息框显示”编译错误:子函数未定义“。据我所知,我正在正确地初始化、填充和使用数组,所以我看不到是什么导致了错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-22 06:12:21

错误非常明确-函数IsInArray()没有在您的代码中定义,至少在您发布的代码片段中没有定义。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54816666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档