I have a macro coded to a rule that autoforwards all incoming and sent emails to a private email address in the BCC field (any auto BCC rule is disabled at the server level.) With the help of the board here, the macro works flawlessly, and for all intents and purposes is invisible.
However, if you open the SENT message in the SENT FOLDER, the BCC field is visible to all for the world to see. I have learned this is a "feature" in Outlook, apparently since 2003.
Is there a way to suppress the visibility of the BCC field when viewing the SENT email?
Or is there a way one can set the display options of an individual folder NOT to display a BCC - EVER?
Thank you for any assistance.
My code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
Dim answer
Dim oAtt
Dim strProc1 As String
On Error GoTo Application_ItemSend_Error
strBcc = "myprivateemail#gmail.com"
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If
Set objRecip = Nothing
On Error GoTo 0
Exit Sub
Application_ItemSend_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " & "Error on
Line " & Erl & " in procedure Application_ItemSend of VBA Document
ThisOutlookSession"
End Sub
If you want to remove BCC recipients in the Sent Items folder, listen for the Items.ItemAdd event on the Sent Items folder, loop through all recipients in the MailItem.Recipients collection and delete recipients with Recipient.Type = olBCC.
"the BCC field is visible to all for the world to see"
Well, if anyone in the world can view your own sent folder, then this is the case. Otherwise the BCC field is not part of the email, recipients do not receive it. The goal of the feature is to have the ability to recall your own BCC messages, so you do not forget that you have sent them.
Try the following...
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim olRec As Outlook.Recipient
Dim Address$
Address = "Om3r#blala.com"
Set olRec = Item.Recipients.Add(Address)
olRec.Type = olBCC
olRec.Resolve
End Sub
Related
We've got multiple users using an existing mailbox on Outlook. Everyone who sends from the mailbox recieves the "sent items" in their own personal mailbox. I've looked in rules and cannot find anything to have the sent items appear in the group mailbox's sent items instead.
I've got the following code, but cannot work out why it's not running.
Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
On Error Resume Next
strBcc = "<mailboxname>"
If Item.SendUsingAccount = "<mailboxname>" Then
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
'Set variable objRecip (recipient) = Item.Recipients.Add (strBcc)
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc")
If res = vbNo Then
Cancel = True
End If
End If
End If
Set objRecip = Nothing
End Sub
To have the mail sent from the mailbox account you need to do the following:
With oMailItem
Set .SendUsingAccount = oOutlook.Session.Accounts.Item(iAccount)
...
End With
Where oMailItem and oOutlook refer to your relevant objects and iAccount is the index number of the mailbox you want to use. In my case I have two mailboxes available to send from, my personal one and the group one. My personal account is first (index 1) and the group mailbox is second (index 2).
Mail Items I send using this code always move to the Sent Items folder in the group mailbox rather than my personal one.
I am looking to create a rule that will conditionally add a BCC recipient depending on the domain name of the To/CC recipients. I have already identified this question as something similar but it doesn't seem to have been resolved.
The starting code is as below:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
On Error Resume Next
' #### USER OPTIONS ####
' address for Bcc -- must be SMTP address or resolvable
' to a name in the address book
strBcc = "SomeEmailAddress#domain.com"
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If
Set objRecip = Nothing
End Sub
In pseudo-code I am looking to add the following conditionals to the strBCC string:
If ToCCRecipientDomain = "#example1.co.uk"
Then strBCC = "email1#trello.com"
ElseIf ToCCRecipientDomain ="#example2.co.uk"
Then strBCC = "email2#trello.com"
ElseIf ToCCRecipientDomain ="#example3.co.uk"
Then strBCC = "email3#trello.com"
Else
Then Cancel = True
End If
For those interested in the application/reason for this, I am looking to create a list of emails sent to a client on a Trello Board for the particular project, which will depend on the email address being sent to.
I think I am close with this as below, simply adding additional If & EndIf lines when additional conditions are required.
If InStr(Item.Recipients.Address, "#example1.co.uk") Then
strBcc = "email1#trello.com"
If InStr(Item.Recipients.Address, "#example2.co.uk") Then
strBcc = "email2#trello.com"
Else
Cancel = True
End If
End If
I was wondering if there is a way i can modify my Item.To in the below code block to test against the physical email address? Right now it is checking against the resolved name.
I.E. if i am testing for #here.com within John.Doe#here.com, and Outlook auto resolves the name, i'm left with a logic test of #here.com <> "John Doe". Simply does not work. Thanks for the assistance! Code follows:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'**************************************************************************************************************************
' Summary: Outlook BCC Insert util based by scan of to field for matching user
' USAGE: populate user options and insert in to the "ThisOutlookSession" code body in Outlook
'**************************************************************************************************************************
' History:
' 05/04/2015 Me Created
'**************************************************************************************************************************
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim EmailToCheckAgainst As String
Dim BCCEmailToAdd As String
On Error Resume Next
' #### USER OPTIONS ####
EmailToCheckAgainst = "#here.com" 'email address you are checking against
BCCEmailToAdd = "BCCme#mycompany.com" 'email address you are adding as BCC
' #### END USER OPTIONS ####
If InStr(LCase(Item.To), LCase(EmailToCheckAgainst)) > 0 Then
Set objRecip = Nothing
Set objRecip = Item.Recipients.Add(BCCEmailToAdd)
objRecip.Type = olBCC
'Resolve it?
Cancel = False
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If
End If
On Error GoTo 0
End Sub
Do no use the To/CC/BCC properties. Loop through all recipients in the MailItem.Recipients collection and compare the Recipient.Address property (if it is resolved) or Recipient.Name if it is not.
Newbie poster with Outlook VBA. Intermediate Excel VBA coder.
I have a VBA routine that autoforwards all incoming email to a Gmail account. It is not all my code, (modified from a blog post) but it works. I need to keep a copy of all my email received in all my accounts so I can consolidate them into one main one. In the Outlook 2010 Exchange account, all the forwarded mail gets saved in the SENT folder as a copy.
Is it possible to delete the autoforwarded copy in the SENT folder, without deleting all SENT emails? I need to keep the emails I actually respond to.
I would not have a problem using conversation mode in the INBOX, to store the replied to emails. but as it now stands, everything is duplicated due to the bcc copy in the SENT folder when I toggle Conversation mode for the INBOX.
Thanks in advance for any assistance.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
On Error Resume Next
' #### USER OPTIONS ####
' address for Bcc -- must be SMTP address or resolvable
' to a name in the address book
strBcc = "bcc.hwb#gmail.com"
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If
Set objRecip = Nothing
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryIDs
Dim objItem
Dim myItem As MailItem
Dim i As Integer
varEntryIDs = Split(EntryIDCollection, ",")
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
'MsgBox (varEntryIDs(i))
Set myItem = objItem.Forward
myItem.Recipients.Add "bcc.hwb#gmail.com"
myItem.Send
'myItem.Delete
Set myItem = Nothing
Next
End Sub
See MailItem.DeleteAfterSubmit Property (Outlook)
myItem.DeleteAfterSubmit = True
How can you get Outlook to warn you if you are about to send and email to an external domain?
Sending large amounts of emails everyday it is always possible to incorrectly send one to the wrong person. This is especially a problem when they are clients or people outside of your company.
Using Alt + Enter to quickly send emails after typing them for me is often the cause as I do not check the recipients thoroughly.
I have found numerous implementations which were not great so I thought I would share mine below...
Thanks ojhhawkins for the code above - really useful. I've done a simple iteration to include a list of the external email addresses in the MsgBox text.
Word of caution - I've noticed that the warning doesn't appear when you use the Send As Email Attachment in other programmes, eg Excel, Adobe Reader etc. As niton pointed out:
Re:Send As Email Attachment in other programmes. Described in notes here outlookcode.com/d/code/setsavefolder.htm "... does not work on messages created with File | Send commands in Office programs or similar commands in Windows Explorer or other programs. Those commands invoke Simple MAPI, which bypasses Outlook functionality."
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim prompt As String
Dim strMsg As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "#example.com") = 0 Then
strMsg = strMsg & " " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
End If
Next
If strMsg <> "" Then
prompt = "This email will be sent outside of example.com to:" & vbNewLine & strMsg & "Do you want to proceed?"
If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub
To actually add this code to your Outlook application:
If you can't see the Developer tab in the ribbon bar, go to File/Options, choose Customise Ribbon on the left, and tick Developer on the right.
From the Developer tab choose Visual Basic.
Expand Project1, Microsoft Outlook Objects, and double-click ThisOutlookSession (top left).
Paste the code above into the module.
Replace the "example.com" in the copied code to your domain.
Close the VBA editor and save changes to the module.
On the Developer tab click Macro Security, and change the level to Notifications for all macros or lower.
Restart Outlook. (The code above will not initialise otherwise.)
Add the below code to the Application_ItemSend event in Outlook & change the domain to your own
Change the Macro Security to either (Notifcations for all macros or Enable all macros)
This will provide you with a warning before sending if 1 or more of your TO,CC or BCC address is not in your domain (eg below #mycompany.com.au)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "#mycompany.com.au") = 0 Then
If MsgBox("Send mail to external domain?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
Exit Sub
Else
Exit Sub
End If
End If
Next
End Sub
I found two add-ins for Outlook that does the same if you don't want to use VBA,
www.safesendsoftware.com and
www.sperrysoftware.com.
This short routine can be saved into the Project1->Microsoft Outlook Objects->ThisOutlookSession window in Visual Basic for Applications (under the Outlook Developer tab in the Ribbon - you have to add it with File->Options->Customize Ribbon) and will work out of the box
https://github.com/guyrleech/Microsoft/blob/master/Check%20Outlook%20recipient%20domains.txt