Outlook 2007中的ItemSend事件中的BCC不再有效

Pix*_*izz 5 email vba bcc outlook-vba

我插入代码ItemSend并保存了ThisOutlookSession模块.它工作一次,不再有效.它保存为VBAproject.OTM,并在重新启动Outlook后打开模块时仍然存在.

Private Sub Application_ItemSend(ByVal Item As Object, _
                                 Cancel As Boolean)
    Dim objRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim strBcc As String
    On Error Resume Next

    ''# #### USER OPTIONS ####
    ''# address for Bcc -- must be SMTP address or resolvable
    ''# to a name in the address book
    strBcc = "someone@somewhere.dom"

    Set objRecip = Item.Recipients.Add(strBcc)
    objRecip.Type = olBCC
    If Not objRecip.Resolve Then
        strMsg = "Could not resolve the Bcc recipient. " & _
                 "Do you want still to send the message?"
        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                "Could Not Resolve Bcc Recipient")
        If res = vbNo Then
            Cancel = True
        End If
    End If

    Set objRecip = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)

Tod*_*ain 2

如果您要挂钩该ItemSend事件,则该事件应该位于类模块中,并且WithEvents您的代码应在常规模块中调用它。另外,您还需要Item.Save对消息进行操作以便密件抄送能够保留。