?
Solved

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

Posted on 2006-11-20
3
Medium Priority
?
1,034 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

752 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