There is an original script found here on Stackoverflow which deals with using VBA script in Outlook to conditionally prevent Outlook from sending email based on from and recipient addresses.
There is another VBA script that I found that automatically added a BCC address to all outgoing email without user intervention when the user clicked on the "Send" button in 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
strBcc = "HR@company.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
What I would like to do is modify this script so that it would change the BCC address being added depending on WHICH email account the user was using to send the email.
For example:
If oMail.AccountThatImSendingFrom = "myself@privateemail.com" Then
strBcc = "myaccount@gmail.com"
ElseIf oMail.AccountThatImSendingFrom = "myself@company.com" Then
strBcc = "HM@company.com"
EndIf
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
I've tried searching extensively, but just can't seem to find a good example that I can adjust.
There is another code example here which I just can't manage to read properly - probably because of all of the imbedded IF statements.
Can anyone help me out or point me in the right direction?
Andrew