1

I want to automatically BCC two email addresses.

I found this code from groovypost.com but it can only BCC one address.

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

End If

Set objRecip = Nothing
Community
  • 1
  • 1

1 Answers1

0

The below adjustments should allow you to enter as many addresses as you want, provided that you split them with a semicolon ;. It creates an array of addresses and repeats the process for as many email iterations exist.

Side note. I did lookup what I presume is this article you mentioned. I noticed that it made the strong claim that this code would not store the BCC record in the sender's sent box. I don't believe this to be true. Thus I'm not sure what the real advantage is to using this VBA code versus just setting up a message rule.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'make sure to separate with ;
Const strBcc As String = "first_email_Address@yopmail.com;second_email_Address@yopmail.com"

Dim objRecip As Recipient, strMsg As String, res As Long, i As Long
'On Error Resume Next

Dim theAddresses() As String
    theAddresses = Split(strBcc, ";", -1)

For i = LBound(theAddresses) To UBound(theAddresses)

    Set objRecip = Item.Recipients.Add(theAddresses(i))
    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
        End If
    End If
Next i

Set objRecip = Nothing
End Sub
halfer
  • 19,824
  • 17
  • 99
  • 186
pgSystemTester
  • 8,979
  • 2
  • 23
  • 49
  • Thanks for this, although I couldn't get this to work. I changed my macro settings and restarted my outlook and still nothing. Would appreciate your help again. – Albert Erestain Jan 26 '21 at 05:41
  • My bad, I'm new to SO so I hope you understand – Albert Erestain Jan 26 '21 at 13:38
  • It's all good. Thanks for accepting. Most likely your issue is with your security parameters in Outlook. Depending on your parameters. This 3 minute video gives a good summation of how to get started. https://youtu.be/zn49D4kXt-U – pgSystemTester Jan 26 '21 at 16:25
  • Oh! Also, make sure you set this procedure within and actual macro send event. First line should be `Application_ItemSend` in it and last line should be `End Sub`. I updated my answer to reflect that. Good luck. – pgSystemTester Jan 26 '21 at 17:18
  • FYI: It does not seem possible to add a rule that add a BCC recipient - I could only add a CC recipient. In my case, I send my outgoing mails to a backup account that I do not want to show in to the other recipients. – le_top Dec 27 '21 at 14:57
  • @le_top I'm almost positive that if you can add a cc recipient, you can add a BCC recipient. Checkout [this post on SO](https://stackoverflow.com/questions/21365624/). Let me know if that works as I've been working with on developing an add-on that indirectly relates to this. – pgSystemTester Dec 27 '21 at 19:13
  • @pgSystemTester You point to a VBA solution. To be precise: Outlook does not seem to allow the creation of a Rule to add a BCC recipient. The VBA code here does allow it, the UI only allows CC. – le_top Dec 28 '21 at 20:32