B R
asked on
Using Outlook VBA to Automatically BCC Emails
I am trying to use a variant of this widely available VBA code to automatically BCC all email sent from Outlook 2007 to 2 email address.
When I send the email I immediately receive the following report into my inbox
Your message did not reach some or all of the intended recipients.
Subject: Subject Here
Sent: 21/09/2011 10:23
The following recipient(s) cannot be reached:
Yet the email addresses are all valid and the emails are being delivered, and the report lists no email addresses.
How do I prevent this report being triggered, why am I receiving it.
Is it a bug in my code or something else? When I only use one email address for BCC it works perfectly.
When the BCC field is filled in manually, everything works properly and I get no errors or reports. This suggests to me that there may be a problem with the code.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'comments
'This version is suitable for Outlook 2003 or later. It uses Outlook objects exclusively and
'includes error handling to avoid problems with an invalid Bcc address.
'Place this VBA code in the built-in ThisOutlookSession module
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 = "email1@somedomain.com"
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
strBcc = "email2@somedomain.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
When I send the email I immediately receive the following report into my inbox
Your message did not reach some or all of the intended recipients.
Subject: Subject Here
Sent: 21/09/2011 10:23
The following recipient(s) cannot be reached:
Yet the email addresses are all valid and the emails are being delivered, and the report lists no email addresses.
How do I prevent this report being triggered, why am I receiving it.
Is it a bug in my code or something else? When I only use one email address for BCC it works perfectly.
When the BCC field is filled in manually, everything works properly and I get no errors or reports. This suggests to me that there may be a problem with the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome. Glad I could help.
ASKER