简体   繁体   English

Outlook 2007 中的 ItemSend 事件中的密件抄送不再有效

[英]BCC in ItemSend event in Outlook 2007 no longer works

I inserted code in ItemSend and saved the ThisOutlookSession module.我在ItemSend插入了代码并保存了 ThisOutlookSession 模块。 It worked once and no longer works.它工作一次,不再工作。 It was saved as VBAproject.OTM and is still there when I open the module after restarting Outlook.它被保存为 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

use and if statement on the Item's Subject field在项目的主题字段上使用和 if 语句

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If Item.Subject = "exact match" Then

    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
    Item.Save

    Set objRecip = Nothing


End If

or use if you want a contains a word in the subject或者如果你想在主题中包含一个词,请使用

If InStr(Item.Subject, "BCCSubject") = 0 Then


End If

If you're hooking the ItemSend event, that should be in a class module with WithEvents and your code to call it in a regular module.如果您正在挂钩ItemSend事件,则该事件应该位于带有WithEvents的类模块中,并且您的代码可以在常规模块中调用它。 Also, you'll want to do an Item.Save on the message for the BCC to stick.此外,您还需要对消息执行Item.Save以便 BCC 坚持。

I was having this issue recently.我最近遇到了这个问题。 It started after the .pst file was corrupted in some way and I had to run scanpst.exe (which I had to search my drive for because the error message does not tell you where it is)它是在 .pst 文件以某种方式损坏之后开始的,我不得不运行 scanpst.exe(我不得不搜索我的驱动器,因为错误消息没有告诉你它在哪里)

After running scanpst.exe and the issue presented itself, this is how I fixed it.运行 scanpst.exe 并出现问题后,我就是这样修复它的。

First, I fiddled with macro security.首先,我摆弄了宏观安全性。 I set it to the lowest setting.我将其设置为最低设置。 Here is a link that covers how to change macro security . 这是一个介绍如何更改宏安全性的链接 Go to Tools > Macro > Security.转至工具 > 宏 > 安全性。 I set it to "No security check for Macros."我将其设置为“对宏不进行安全检查”。

Then I used this exact code:然后我使用了这个确切的代码:

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 = "PUT YOUR EMAIL ADDRESS HERE AND LEAVE THE QUOTES"

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

Then I clicked the save button then little green play button to run the macro.然后我点击保存按钮,然后点击绿色的小播放按钮来运行宏。 It asked me for a Macro name.它要求我提供一个宏名称。 I used bccUsername and clicked create.我使用了 bccUsername 并单击了创建。 The editor added a section called Modules under ThisOutLookSession .编辑器在ThisOutLookSession下添加了一个名为Modules的部分。

I then restarted Outlook and tested twice and it worked.然后我重新启动了 Outlook 并测试了两次,它起作用了。

I'm not exactly sure what I did that made it start working again, but this is not too involved with the steps so hopefully this helps you and others with the same problem.我不确定我做了什么让它再次开始工作,但这并没有涉及到这些步骤,所以希望这可以帮助你和其他有同样问题的人。

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

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