How to get warning when sending email to external domain in Outlook?
While using Outlook, how can you prevent sending emails accidentally to recipients outside your company? Actually, you can display warning box when sending email to external domain in Outlook. This article will introduce a VBA method to achieve it.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
The following VBA code can help you get warning when sending email to external domain in Outlook. Please do as follows.
1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession to open the ThisOutlookSession (Code) window, and then copy below VBA code into the window. See screenshot:
VBA code: Get warning when sending email to external domain
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 'Update by Extendoffice 20180504 Dim xMailItem As Outlook.MailItem Dim xRecipients As Outlook.Recipients Dim i As Long Dim xRecipientAddress As String Dim xPrompt As String Dim xYesNo As Integer Dim xPos As Integer On Error Resume Next If Item.Class <> olMail Then Exit Sub Set xMailItem = Item Set xRecipients = xMailItem.Recipients For i = xRecipients.Count To 1 Step -1 xRecipientAddress = xRecipients.Item(i).Address xPos = InStrRev(LCase(xRecipientAddress), "@addin99.com") If xPos <= 0 Then Exit For Cancel = False Next If InStrRev(LCase(xRecipientAddress), "@addin99.com") > 0 Then Exit Sub xPrompt = "Are you sure to send this email to outside your company? " xYesNo = MsgBox(xPrompt, vbYesNo + vbQuestion, "Kutools for Outlook") If xYesNo = vbNo Then Cancel = True End Sub
Note: In the code, “@addin99.com” is the internal email domain you will send emails to. Please change it as you need.
From now on, when clicking Send button to send emails to external email domain (not the internal email domain you specified in the VBA code), a warning box will pop up as below screenshot shown.
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 1 months agoDoesn't work, no pop-up is showing.
To post as a guest, your comment is unpublished.· 3 months agoI had the same problem - getting warning also for the internal e-mails.
When the internal e-mail address from Directory is used, xRecipientAddress does not return the address, but some weird exchange string like /O=<organization...> - try to print it in MsgBox and you will see yours.
To post as a guest, your comment is unpublished.· 4 months agoThis does not work. I do not get a pop up for internal or external.
To post as a guest, your comment is unpublished.· 4 months agoThis is prompting both internal and external emails. both domain fields have been updated. Any thoughts? Many thanks
To post as a guest, your comment is unpublished.· 6 months agoHola:
Gran aporte pero me lo pregunta para todos los envíos y no solo para los de una determinada dirección. Es decir, siempre me sale el mensaje independientemente del dominio... ¿está bien el código? Gracias.