<

Automatically CC/BCC Outlook Messages

Published on
22,568 Points
12,268 Views
8 Endorsements
Last Modified:
Awarded
Community Pick

Bill is an employee at Acme, Inc (a hypothetical company).  Jane, Bill’s boss, wants to be copied on all Bill’s messages.  Why she wants to be copied is immaterial.  She’s the boss.  Bill is pretty good about remembering to add her to the CC line, but sometimes he forgets.  He forgot to add her to a message today, a really important one that got him in trouble with Jane.  She didn’t know what Bill had said in the message and said some things in a meeting that contradicted what Bill had said.  On returning from the meeting Jane chewed Bill out severely.  Now he’s concerned that Jane might fire him if he ever forgets to copy her on another message.

Maybe you aren’t in Bill’s shoes, but there are a good number of managers who want to be copied on all messages or at least all those for a given subject, project, etc.  Sometimes it’s because the boss is a micromanager.  In other cases it’s because these are hot topic messages and the boss needs to be informed.  It might not even be the boss who wants to be copied.  Maybe you’re a member of a team and copying your team mates is the only way to ensure they are informed.  Whatever the reason, there are clearly some circumstances where copying someone else on all messages or on all messages meeting some criteria is required.  The choice then is to remember to add those folks to the CC/BCC line manually on a per message basis, or to employ automation to do the work for you.  I’d rather automate the process so I don’t HAVE to remember.

If we want to automate this, what are our options?  Outlook has a rules feature.  Can we use it to do this?  The answer is “it depends”.  If you only want to copy (i.e., CC) the message, then the answer is yes.  If you need to blind copy (i.e., BCC) an address, then the answer is no.  How about a third-party solution?  Yes, there are third-party solutions available.  These solutions are called add-ins and there are several of them on the market.  The downside is that they aren’t free.  I don’t believe they are terribly expensive, I’ve never used or purchased one, but there is a cost.  There is a free alternative though and who doesn't like free?  The free solution is to write a script.

Before I talk about the scripted approach I need to say a few more words about why you would consider a scripted approach when Outlook’s built-in rules will get the job done at least for CCing messages.  Rules have limits,  two of them: conditions and size.  A rule is limited to the conditions offered by the rules wizard.  If you need something outside of one of those conditions, then you’re out of luck.  Outlook limits the aggregate size of all rules to 32K (see this Microsoft KB article for details).  It’s impossible to equate 32K to an exact number of rules, but it’s easier than you might think to run afoul of this limit.  In contrast, scripts do not suffer from either of these constraints.  The only constraints on building conditions are the existence of a message property for the condition to work against and your ability to write a conditional statement.  There are no size constraints on scripts.

Outlook’s scripting capabilities give it a lot of power.  It allows you to add functionality to the product with relative ease.  In this case it gives us the ability to copy messages to a boss, teammate, or anyone we choose as they are sent in as little as 8 lines of code.  Of course copying all messages to one address represents the simplest condition.  What about copying messages that meeting a condition or copying to different people based on different conditions?  As you might expect that takes a bit more code.  Not a lot more though.  In the following sections I’ve posted code that handles conditions ranging from very simple (i.e. flatly copy all messages to a given address) to moderately complex (i.e. copy to different persons/groups based on some criteria).

Scenario #1.  CC or BCC all messages to one or more addresses.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
	‘Repeat the next two lines for each address you want to copy to.’
       Set olkRecipient = Item.Recipients.Add("someone@company.com")	   ‘<- Change the address’
olkRecipient.Type = olCC    ‘<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.’
        Item.Save
    End If
End Sub

Open in new window


Scenario #2.  CC or BCC all messages that have a certain word/phrase in the subject.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
        If InStr(1, Item.Subject, "Keyword/phrase") Then                               '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("someone@company.com")    '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
    End If
End Sub

Open in new window


Scenario #3.  CC or BCC to different addresses based on words/phrases in the subject.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
        If InStr(1, Item.Subject, "First keyword/phrase") Then                        '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("address1@company.com")    '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
        If InStr(1, Item.Subject, "Second keyword/phrase") Then                   '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("address2@company.com")   '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
    End If
End Sub

Open in new window


Scenario #4.  CC or BCC to different addresses based on a category assigned to the message.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, arrCats As Variant, varCat As Variant
    If Item.Class = olMail Then
        arrCats = Split(Item.Categories, ",")
        For Each varCat In arrCats
            Select Case varCat
                Case "ProjectX"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("ProjectX@company.com")  '<- Change the address'
                    olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
                Case "ProjectY"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("ProjectY@company.com")  '<- Change the address'
                    olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
                Case "Reports"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("someone@company.com")  '<- Change the address'
                    olkRecipient.Type = olBCC  '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            End Select
        Next
        Item.Save
    End If
End Sub

Open in new window


These four scenarios don’t represent all the possibilities.  There are other conditions you could key on (e.g. who the message is addressed to, words or phrases in the body of the message).  This should be enough to get you started.  If you have a scenario that isn’t covered by the examples, then post a comment with the details and I’ll consider adding it to the article.

Adding the Code to Outlook.

Outlook 2003 and Earlier.
  1.  Start Outlook
  2.  Click Tools > Macro > Visual Basic Editor
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
  5.  Outlook's VB Editor window
  6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
  7.  Click the diskette icon on the toolbar to save the changes
  8.  Close the VB Editor
  9.  Click Tools > Macro > Security
10.  Set the Security Level to Medium
11.  Close Outlook
12.  Start Outlook
13.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Outlook 2007.
  1.  Start Outlook.
  2.  Click Tools > Macro > Visual Basic Editor.
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession.
  4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's
       VB Editor window.
  5.  Edit the code as needed.  I included comment lines wherever something needs to or can change.
  6.  Click the diskette icon on the toolbar to save the changes.
  7.  Close the VB Editor.
  8.  Click Tools > Trust Center.
  9.  Click Macro Security.
10.  Set Macro Security to "Warnings for all macros".
11.  Click OK.
12.  Close Outlook.
13.  Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Summary.

Whether you're in Bill’s shoes or not I hope you find this article useful.  My goal was to show you a simple way to use Outlook’s automation capabilities to perform a routine task and leave you free to concentrate on other, hopefully more important matters.  Although I cannot honestly claim that I’ve implemented all the principles that David Allen laid out in his book “Getting Things Done”, I do practice his "get it all out of your head" principle whenever possible.  Automating a task, even a simple one like remembering to copy messages to someone else, gives me one less thing to remember.  If you only need to CC an address, the condition you need to apply is a simple one, and you do not already have too many rules, then using the rules wizard is your best bet.  If instead you need to BCC an address, you have complex conditions or the rules wizard doesn’t offer a suitable condition, or you already have a plethora of rules and adding more could push you past the 32K limit, then the solution I’ve presented here is probably for you.

Notes.

I've yet to test this in Outlook 2010.  I believe it will work, but until I've tested it I don't want to make an unsupported statement that it will.
If you already have an ItemSend subroutine that contains code, then you will have to merge this code with that you already have.  Post a comment to this article or open a new question and reference this article and I'll be glad to help you integrate this code with your code.
8
Comment
Author:David Lee
0 Comments

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Join & Write a Comment

If you, like me, have a dislike for using Online Subscription anti-spam services, then this video series is for you. I have an inherent dislike of leaving decisions such as what is and what isn't spamming to other people or services for me and insis…
This is Part-2 of Learning to use the Power of Mailwasher Pro so if you haven't watched Part-1 yet, I urge you to do so before watching this video. Click this link to watch Part-1 (https://www.experts-exchange.com/videos/56638/Learn-to-use-the-POWER…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month