I am looking to create a rule that will conditionally add a BCC recipient depending on the domain name of the To/CC recipients. 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:
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.