Warn before sending emails to external domains in Outlook Warn before sending emails to external domains in Outlook vba vba

Warn before sending emails to external domains in Outlook


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 IfEnd 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.)


  1. Add the below code to the Application_ItemSend event in Outlook & change the domain to your own

  2. 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    NextEnd Sub


I found two add-ins for Outlook that does the same if you don't want to use VBA,