Link to home
Start Free TrialLog in
Avatar of dbdp
dbdp

asked on

Auto BCC an outlook message and add to subject

I need to auto bcc every message I send through outlook (which is easy with VBA)BUT I also need to add text to the BCC subject though not the original one.

Is this possible?

I.E Original message gets sent as is with subject 'My Subject' ,  and BBC message has subject 'BBC - My Subject'
Avatar of omgang
omgang
Flag of United States of America image

Not possible with a single message.  Consider that you're sending one message to a list of recipients.  Some of the recipients are listed in the To: field, some in the CC: field and some in the BCC: field.  It's still a single message being sent but it's distribution is being handled by the outbound mail server based upon the recipients in each of those fields.  What you're asking would require the mail server itself to modify the message before sending to BCC recipients.

You could create a routine in Outlook to automatically draft a copy of each message, modify the subject line accordingly and send it to a specified list of recipients but this will actually be a second message.  It will either end up in your Sent Items folder as a second message or not if you specifically choose not to save it in your Sent Items.  The original message will not be updated to show a BCC was added.

OM Gang
Avatar of dbdp
dbdp

ASKER

Yes that would be fine too, I thought of it but not sure how to do it,

Any ideas?
Well, I opened VBE in Outlook and I already had a procedure that did something very similiar....must be from a PAQ here on EE.  Anyway, I modified it a bit for your Q.  This does what you want.  Note that I added a For loop to enumerate the list of recipients and remove each one.  This is to prevent resending the copy of the message to the original recipients.  You'll need to add additional For..Next loops for CC recipients and BCC recipients; we need to remove all previous recipients so the second message is only sent to our designated BCC.  If desirable, you could add each existing recipient, from each For...Next loop, to string variables and then insert these string variables into the beginning of the message Body, e.g. "Original recipients included:  " & strRecips & vbCrLf & "CC:  " & strCC & vbCrLf & "BCC:  " & strBCC

OM Gang



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo Err_Application_ItemSend

    Dim NewItem As Outlook.MailItem
    Dim i As Integer
    Dim strBCCAddy As String, strNewSubject As String
   
        'address we want to send a copy of every message to
    strBCCAddy = "omgang@ee.com"
        'text we'll prepend to each subject line
    strNewSubject = "BCC -- "
   
        'use Outlook mailitem.copy method to grab a copy of the current mailitem object
    Set NewItem = Item.Copy
        'enumerate recipient list and remove each
    For i = 1 To NewItem.Recipients.Count
        NewItem.Recipients.Remove (i)
    Next i
        'now add our desired recipient
    NewItem.Recipients.Add (strBCCAddy)
        'modify the subject line
    NewItem.Subject = strNewSubject & NewItem.Subject
        'send the copy we just made
    NewItem.Send

Exit_Application_ItemSend:
        'destroy object variable
    Set NewItem = Nothing
    Exit Sub

Err_Application_ItemSend:
    MsgBox Err.Number & " (" & Err.Description & ") in procedure Application_ItemSend of VBA Document ThisOutlookSession"
    Resume Exit_Application_ItemSend

End Sub
Forgot to mention that you should add that procedure to the
ThisOutlookSession
class module

OM Gang
Avatar of dbdp

ASKER

I tried the code and it makes sense to me, but nothing seems to happen.

Any ideas as to why?
ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbdp

ASKER

Was the macros :)