Using Outlook's ItemSend Event to BCC Emails
February 5, 2010 • JP • 8 Comments • Rate 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:
- 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")).
- 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.
- 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.
Previous Post: ShipTrack 4.1.2 update available
Next Post: Customize the Task Pane




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
Sure Ray, just check out http://www.codeforexcelandoutlook.com/blog/2008/04/event-code-for-forwarding-selected-text/
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.
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:
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
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
Your code should check that it's a MailItem first.
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
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.