Solved

Automatic BCC on all e-mails sent from one outlook account not both

Posted on 2006-11-20
3
1,025 Views
Last Modified: 2008-03-10
Hi,

I have read and tested all the solutions mentioned on this forum for automatically BCC'ing e-mails to an address.

The problem I am having is that we have 2 e-mail accounts in Outlook and only want one of these accounts to BCC the address not both.

I am using the following code at the moment :

'-----------------------------------------------------------------------
'Macro Begins Here
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMeBCC As Recipient
    'If the item is a message
    'If Item.Class = olMail Then
        'Trigger the code if the sender name matches
        'If Item.SenderEmailAddress = "Email@address.co.uk" Then
            'Add a recipient
            Set objMeBCC = Item.Recipients.Add("Email@address.co.uk")
            'Set the recipient type to BCC
            objMeBCC.Type = olBCC
            objMeBCC.Resolve
            'Item.Recipients.ResolveAll
       End If
    'End If
    'Allow the message to be sent
    Cancel = False
End Sub
'Macro Ends Here
'-----------------------------------------------------------------------

Is there anything that I can add that will select just one account to BCC from?

We have tried using 'If Item.SenderEmailAddress = "Email@address.co.uk" and 'If Item.SenderName = "Email_account_Name_1" but neither of these seem to work. It stops any address being BCC'd

Kind Regards

Barry Thomas
0
Comment
Question by:milbank
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 18013441
Hi, Barry.

Try this.  It detects the account each item is being sent through.  If it works, then you just need to add the code that handles adding the BCC.

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
    Item.Save
    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
    objCDO.Logoff
    Set objCDO = Nothing
    Cancel = True
End Sub
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Outlook Free & Paid Tools
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now