BCC automatically on one of two accounts

Posted on 2008-10-22
Medium Priority
Last Modified: 2012-05-05
I would like to have emails sent from a particular account sent with a BCC automatically.

I've found the attached code snippet for automatically populating the BCC field when an email is sent, placed it in 'ThisOutlookSession' of the VBA editor but it doesn't seem to work. I've gone in and placed a breakpoint but it never seems to fire.

In addition, I would like to have the BCC populate only on one of my two email accounts. How can I do that?
the second piece of code below is supposed to do that but it doesn't seem to fire either.....


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 = "sburrows@hisconsulting.net"
    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
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objCDO As MAPI.Session, _
        objMsg As MAPI.message, _
        colFields As MAPI.Fields, _
        objField As MAPI.Field, _
        strAccountName As String
    Set objCDO = CreateObject("MAPI.Session")
    objCDO.Logon "", "", False, False
    Set objMsg = objCDO.GetMessage(Item.EntryID, Item.Parent.StoreID)
    Set colFields = objMsg.Fields
    On Error Resume Next
    strAccountName = colFields.Item(&H8014001E)
    If Err.Number = -2147221233 Then
        strAccountName = "Default Account"
    End If
    On Error GoTo 0
    Select Case strAccountName
        Case "pop1.company.com"
            Debug.Print "Account1"
        Case "pop2.company.com"
            Debug.Print "Account2"
        Case "Default Account"
            Debug.Print "Default"
    End Select
    Set objMsg = Nothing
    Set objField = Nothing
    Set colFields = Nothing
    Set objCDO = Nothing
    Cancel = True
End Sub

Open in new window

Question by:scbdpm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 76

Expert Comment

by:David Lee
ID: 22777439
Hi, scbdpm.

First, there are two subroutines with the same name.  That's illegal.  Outlook won't run either one.  Remove one or the other.  Also, make sure that macros are enabled in Outlook.

Author Comment

ID: 22778085
that's not the case.
I've tried each seaprately and neither one fires!
LVL 76

Expert Comment

by:David Lee
ID: 22778166
Ok, didn't know that.  They were posted together, so it looked to me as if they were both in use.  Have you verified that macros are enabled in Outlook?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22778190
Have 2007. Am new to it.... is this done in Trust Center?
Not sure, could you provide guidance.....

Author Comment

ID: 22779392
ok, so I got the macros working.
Now, I am not getting the correct account. I am always getting 'Default Account"....
can you help?
LVL 76

Accepted Solution

David Lee earned 2000 total points
ID: 22782348
On closer look neither of those macros are for Outlook 2007.  Use this version instead.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
        'Change the address on the following line'
        If Item.SendUsingAccount.DisplayName = "myaccount@mycompany.com" Then
            'Change the address on the following line'
            Set olkRecipient = Item.Recipients.Add("someone@company.com")
            olkRecipient.Type = olBCC
        End If
    End If
End Sub

Open in new window


Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question