[英]Outlook 2007 VBA - BCC depending on To/CC Recipients
I am looking to create a rule that will conditionally add a BCC recipient depending on the domain name of the To/CC recipients.我希望创建一个规则,该规则将根据 To/CC 收件人的域名有条件地添加 BCC 收件人。 I have already identified this question as something similar but it doesn't seem to have been resolved.我已经将这个问题确定为类似的问题,但似乎尚未解决。
The starting code is as below:起始代码如下:
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 = "SomeEmailAddress@domain.com"
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
In pseudo-code I am looking to add the following conditionals to the strBCC string:在伪代码中,我希望将以下条件添加到 strBCC 字符串中:
If ToCCRecipientDomain = "@example1.co.uk"
Then strBCC = "email1@trello.com"
ElseIf ToCCRecipientDomain ="@example2.co.uk"
Then strBCC = "email2@trello.com"
ElseIf ToCCRecipientDomain ="@example3.co.uk"
Then strBCC = "email3@trello.com"
Else
Then Cancel = True
End If
For those interested in the application/reason for this, I am looking to create a list of emails sent to a client on a Trello Board for the particular project, which will depend on the email address being sent to.对于那些对此应用程序/原因感兴趣的人,我希望为特定项目在 Trello Board 上创建发送给客户的电子邮件列表,这取决于发送到的电子邮件地址。
I think I am close with this as below, simply adding additional If & EndIf lines when additional conditions are required.我想我很接近这个,如下所示,只需在需要额外条件时添加额外的 If & EndIf 行。
If InStr(Item.Recipients.Address, "@example1.co.uk") Then
strBcc = "email1@trello.com"
If InStr(Item.Recipients.Address, "@example2.co.uk") Then
strBcc = "email2@trello.com"
Else
Cancel = True
End If
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.