Solved

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

Posted on 2006-11-20
3
1,027 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
Outlook Free & Paid Tools
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

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