Using Outlook's ItemSend Event to BCC Emails

February 5, 2010JP8 CommentsRate This Article


Browsing Google Blogs for VBA blog posts is an excellent use of your time. This time, I found a blog post on Windows Live by Michael Lu called Outlook Auto BCC VBA. He posted code that uses the ItemSend event to automatically add (and resolve) a BCC Recipient to outgoing emails.

I won't repost his code here; visit his post for that. What I will do is repost my comments, and add some more.

You do not need to resolve an email address; it will always resolve. Call the Resolve method on names you want to compare against the address book.

FYI- If you click Yes on the "Can not parse BCC email address" messagebox, the Cancel statement is skipped, but Outlook will still attempt to send the message with the unresolved recipient.

I forgot one other thing: The code doesn't check, but simply assumes that the outgoing item is an email and tries to add a Recipient to it. I can't predict the result if the item is actually a meeting request or task assignment.

So there are three things I wanted to point out here:

  1. Use the Recipient.Resolve or Recipients.ResolveAll methods if you're adding Recipients to an item as proper names (i.e. Item.Recipients.Add("Dan Wilson")). It's not necessary to resolve email addresses (eg: Item.Recipients.Add("dan.wilson@microsoft.com")).
  2. If a Recipient cannot be resolved, you'll see a dialog box from Outlook asking you to resolve the name manually. This may not be what you want (your end users) to see.
  3. Make sure the properties and methods you are calling are appropriate for the specific type of object you expect (if you use the generic Object type) or cast Object types into more specific types before working with them.

About JP
I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space if you want to learn more about VBA. Keep Reading »

↑ Scroll to top
Previous Post:

Next Post:

8 Response(s) to Using Outlook's ItemSend Event to BCC Emails ↓

  1. Ray says:

    Jimmy -

    Love the Outlook automation … just about every post is useful in one way or another! On a subject somewhat related to this post — is there a way to auto-forward an email? Of course there's the built-in forwarding utility, but my company has turned that off …

    I'd like to be able to forward emails from a specific sender to an external email address ….

    Thanks alot — keep up the great work!

    Regards,
    ray

  2. sam says:

    Kind of OT.

    But is there a way to set a Rule for the Sent box folder which "MOVES" (Not copy) a mail sent to a specific e-mail address in to a different folder.

    • JP says:

      In the Rules Wizard (Outlook 2003) I only see the option to move a copy to another folder. So you'd need VBA to do this. For example (this is air code), let's say you wanted to save messages sent to a specific person to an Inbox subfolder for that person's name:

      Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

      On Error Goto ErrorHandler

      Dim Msg As Outlook.MailItem
      Dim moveFolder As Outlook.MAPIFolder

      If TypeName(Item) <> "MailItem" Then Goto ProgramExit

      Set Msg = Item
      Set moveFolder = Outlook.Session.GetDefaultFolders(olFolderInbox).Folders(Msg.To)

      If Msg.To = "your recipient" Then
        Set Msg.SaveSentMessageFolder = moveFolder
      End If

      ProgramExit:
        Exit Sub
      ErrorHandler:
        MsgBox Err.Number & " - " & Err.Description
        Resume ProgramExit
      End Sub
  3. Armando Montes says:

    I found this short code for BCC:
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
    Boolean)
    Item.BCC = "address@domain.de"
    Item.Recipients.ResolveAll
    End Sub
    http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?query=bcc&dg=microsoft.public.outlook.program_vba&cat=en_US_f2349ded-ffa8-474e-a28d-ef611f1d45b4&lang=en&cr=US&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us

    • JP says:

      Your code should check that it's a MailItem first.

      • Armando Montes says:

        Thanks for your help, succesfully tested this and is working:
        Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim R As Outlook.Recipient
        Dim Address$

        Address = "abc@domain.com"

        Set R = Item.Recipients.Add(Address)
        R.Type = olBCC
        R.Resolve
        End Sub
        Do you know this DLL?
        Thanks again,
        Armando

        • JP says:

          What I'm saying is that your code assumes that the outgoing item is a MailItem. You want to check for that before trying to add a recipient.

Speak Your Mind

Tell us what you're thinking...

Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].




Site last updated July 26, 2010 @ 8:14 pm