如何使用 VBA 将 Outlook 2007 自动密件抄送邮件发送到主题中包含特定单词的特定电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2588660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:30:48  来源:igfitidea点击:

How can I make Outlook 2007 auto BCC messages to a specific email with specific words in subject using VBA?

vbaoutlookoutlook-2007outlook-vba

提问by tgadd

Possible Duplicate:
Outlook VBA to BCC emails sent not working in Outlook 2007

可能重复:
Outlook VBA 到 BCC 发送的电子邮件在 Outlook 2007 中不起作用

So far I have this code from outlookcode.com which I can get to work sending all emails I send to the BCC email. I am not a developer, so I don't have a lot of context to go about editing this myself, or even approaching researching this. If anyone knows how to make this check for words in the subject, or check if the subject equals a certain string, I'd really appreciate it.

到目前为止,我从 Outlookcode.com 获得了这段代码,我可以开始工作,将我发送到 BCC 电子邮件的所有电子邮件发送出去。我不是开发人员,所以我没有很多背景可以自己编辑这个,甚至没有研究这个。如果有人知道如何检查主题中的单词,或者检查主题是否等于某个字符串,我真的很感激。

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 = "[email protected]"

    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

回答by user1069275

If you don't want to get involved with VB, you could do this with the rules wizard as follows:

如果您不想参与 VB,您可以使用规则向导执行此操作,如下所示:

  1. Create one rule and make it your last rule. This rule should be applied when your name is in the To or Cc fields. And it should stop processing subsequent rules: Step 1: Select conditions: Where my name is in the To or Cc box. Step 2: Select actions: Stop processing more rules.
  2. Create another rule and add it to the bottom of rule create at step 1 above. Make it as follows: Step 1: Select conditions: Where my name is not in the To box. Step 2: do whatever you want with you BCC message here.
  1. 创建一条规则并将其作为最后一条规则。当您的姓名在收件人或抄送字段中时,应应用此规则。并且它应该停止处理后续规则: 第 1 步:选择条件:我的名字在“收件人”或“抄送”框中的位置。步骤 2:选择操作:停止处理更多规则。
  2. 创建另一个规则并将其添加到上面步骤 1 中创建的规则的底部。按如下方式进行: 步骤 1:选择条件:我的名字不在收件人框中。第 2 步:在这里对您的 BCC 消息做任何您想做的事情。

So, the thing with the procedure above is that if you reached the rule created on step 2 is because you received a message where your name is not in the To or Cc fields, i.e. you are in the Bcc field.

因此,上述过程的问题是,如果您达到了在步骤 2 中创建的规则,是因为您收到一条消息,其中您的姓名不在收件人或抄送字段中,即您在密件抄送字段中。

You just need those two rules because there is no such condition as "Where my name is NOT in the To or Cc box". But we can manage to do the same with the above workaround.

您只需要这两个规则,因为没有“我的名字不在收件人或抄送框中的位置”这样的条件。但是我们可以设法用上述解决方法做同样的事情。