Solved

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

Posted on 2006-11-20
3
1,030 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
[X]
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 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

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Read this checklist to learn more about the 15 things you should never include in an email signature.
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…

739 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