VB code to BCC someone based on recipient

I need some VB code to BCC an email address based on the the recipient of the outgoing email. Outlook 2003 rules is able to create a rule; when sending email to X carbon copy Y, but I need it to blind carbon copy which their is no option for in outlook's rules.

I found the below code at outlookcode.com, which will BCC a specified address on ALL outgoing messages from that outlook client, but I only want it to BCC the message based on it sending to a specified address.

Is anyone able to take the below code and modify it? If sending to X BCC Y

Thanks for any suggestions!


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMe As Recipient
    Set objMe = Item.Recipients.Add("myaddress@mydomain.dom")
    objMe.Type = olBCC
    objMe.Resolve
    Set objMe = Nothing
End Sub
MooliganAsked:
Who is Participating?
 
mdiglioConnect With a Mentor Commented:
Hello,
This came from Sue Mosher
http://www.outlookcode.com/d/code/autoaddrecip.htm


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objMe As Recipient
if test(item) then
    Set objMe = Item.Recipients.Add("myaddress@mydomain.dom")
    objMe.Type = olBCC
    objMe.Resolve
    Set objMe = Nothing
end if
End Sub

Function test(objMail As Outlook.MailItem) As Boolean
Dim objRecip As Outlook.Recipient
For Each objRecip In objMail.Recipients
'when sending email to X carbon copy Y...Enter X's email address here :
    If objRecip = "Enter_EMAIL_HERE" Then
        test = True
     End If
Next
End Function




0
 
MooliganAuthor Commented:
Thanks this works great except for the security warnings.
I've installed the redemption libraries and am now trying to incorporate her second redemption code example but I'm having trouble.

Below is what I have so far but I em getting a type mismatch on If test(item) Then
Thoughts on that?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMe As Redemption.SafeRecipient
    Dim sMail As Redemption.SafeMailItem
    Set sMail = CreateObject("Redemption.SafeMailItem")
    Item.Save
    sMail.Item = Item
    If test(Item) Then
        Set objMe = sMail.Recipients.Add("jason.congdon@absu.accenture.com")
        objMe.Type = olBCC
        objMe.Resolve
        Set objMe = Nothing
        Set sMail = Nothing
    End If
 
End Sub



Function test(objMail As Redemption.SafeMailItem) As Boolean
Dim objrecip As Redemption.SafeRecipient
For Each objrecip In objMail.Recipients
'when sending email to X carbon copy Y...Enter X's email address here :
    If objrecip = "jason.congdon@gmail.com" Then
        test = True
     End If
Next
End Function
0
 
mdiglioCommented:
Sorry I never heard of the redemption thing before now.
I'll take a look at it.

What secuirty warnings are you referring to?
The one that says something like 'A program is trying to send an email" ?
I use this free software to bypass some of the Outlook secuirty problems.

Advanced Security for Outlook
http://www.mapilab.com/outlook/security/
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
MooliganAuthor Commented:
Yes that is the exact warning I am referring too.

I just tried that mapilab software and this looks perfect! I just tried it on mine and I think this is going to do the job perfectly.

I'm thrilled, just going to do a few more tests.

Thanks for being so prompt!
0
 
Rory ArchibaldCommented:
Hi Mooligan,
It soundslike you may have already sorted out your problem, but just for your information, the reason your code was erroring is because you had changed the test function to accept a Redemption.SafeMailItem as an argument but when you call it with test(Item) you are actually passing an Outlook.Mailitem. You would need to use test(smail) for it to work.
HTH

Rory
0
 
MooliganAuthor Commented:
Thanks for the suggestion rory but for now I am going to go with that suggested mapilab program.

Thanks for the help mdiglio, works great.
0
 
mdiglioCommented:
glad it worked for you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.