撰写电子邮件时,是否可以获取收件人的联系人类别?

时间:2018-12-21 20:02:00

标签: vba outlook

我已将我的联系人分配到各种类别。因此,我想创建一个规则,以便如果我将电子邮件发送给该类别之一中的任何联系人,则该电子邮件将被密件抄送至电子邮件地址。

这是我当前拥有的代码,我不断收到错误{438} Set oContact = oRecip.GetContact

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim oContact As Outlook.ContactItem
    Dim oRecip
    Dim Recip As Recipient
    Dim BccRecip As String
    Dim strCategoryName As String



Set oRecipients = Item.Recipients
Set oRecipient = Recipients(1)

    Set oContact = oRecipient.GetContact

    strCategoryName = oContact.Categories


    strCategoryName = oContact.Categories

    If InStr(LCase(strCategoryName), "test") > 0 Then
        BccRecip = "abc@def.com"
    Else
        Exit Sub
    End If


    Set Recip = Item.Recipients.Add(BccRecip)
    Recip.Type = olBCC

    If Recip.Resolve Then
        Cancel = False
    Else
        Cancel = True
    End If
End Sub

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

代码中的

oRecip是收件人的集合。

您必须使用类似

   Set oRecipients = Item.Recipients
   Set oRecipient = Recipients(1)