Warn before sending messages to the wrong email address

Last reviewed on September 20, 2014

I pick up interesting problems looking for solutions on various forums, such as this one.

Can I create an Outlook Rule that will keep me from sending an email to the wrong address? The reason: I have various email addresses. On occasion, I intend to send a message to my own address and use the wrong address instead, sending an email to the same wrong person more than once.

You can't use a rule to protect you from yourself but if you realize it as soon as you hit send, you can use a rule to delay mail by a minute or two, to give you time to recover the message and change the address. I have more information at Defer delivery in Outlook. You could also disable autocomplete, since it is the main cause of this problem, but because its a very good time saver most of the time, a macro is better.

Alternately, you can use macros to help get the address right. Since the problem is likely due to your selecting the wrong address as you type in the To field, using macros to create and address messages will reduce some, if not all of the problems. You can also use a macro to check outgoing messages for an address.

Forward selected message to specific address

Create a macro for you address and assign the macro to a toolbar or ribbon button. Place the button(s) next to the Forward button to help you remember. You'll need one macro & button for each address you forward messages to.

Public Sub ForwardtoMe()
Dim oMail As Outlook.MailItem

Set oMail = Application.ActiveExplorer.Selection(1).Forward
oMail.Recipients.Add ("alias@domain.com")
    oMail.Display
  
End Sub

 

Check messages you send

This macro checks messages for one specific address and if it finds the address, allows you to cancel the send. On Error Resume Next allows it to work with meetings or task requests, otherwise it kicks up an error message.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
On Error Resume Next
 ' use lower case for the address 
 ' LCase converts all addresses in the To field to lower case
If InStr(LCase(Item.To), "bad@address.com") Then
      Prompt$ = "You sending this to " & Item.To & ". Are you sure you want to send it?"
       If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
         Cancel = True
       End If
  End If
    
End Sub

A slightly different version of the above macro checks messages you send for one of several addresses. If the address on the message is not one in the list (or there are multiple addresses in the list), it will ask if you really want to send.

While not the best option in my opinion, because it basically asks for confirmation every time you send, it may be a good solution in some cases.

To use, add your addresses to the Case line. This macro needs to be added to ThisOutlookSession to work.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    On Error Resume Next
   Select Case LCase(Item.To)
    Case "alias@domain.com", "alias2@domain3.com", "alias3@domain3.com"
        Item.Send
    Case Else
      Prompt$ = "You are not sending this to " & Item.To & ". Are you sure you want to send the Mail?"
       If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
         Cancel = True
       End If
    
    End Select
    
End Sub

 

Check addresses in the To, CC, or BCC field using the Recipient Collection

This variation of the code checks all addresses in the recipient collection against the "bad address".

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
     
  Dim Recipients As Outlook.Recipients
  Dim recip As Outlook.Recipient
  Dim i
  Dim prompt As String
  
On Error Resume Next
 ' use lower case for the address
 ' LCase converts all addresses in the To field to lower case
 
 Set Recipients = Item.Recipients
  For i = Recipients.Count To 1 Step -1
    Set recip = Recipients.Item(i)
    
 If InStr(LCase(recip), "bad@address.com") Then
      prompt$ = "You sending this to this to " & Item.To & ". Are you sure you want to send it?"
       If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
         Cancel = True
       End If
  End If

Next i
 
     
End Sub

 

Check new messages you send

A user with three accounts in his profile wanted to be reminded which email account was sending the message, but because Outlook always sends replies and forwards using the account that downloaded the message, he only want to check new messages.

The result is this code sample which checks new messages on send while skipping replies and forwards. It looks for RE: or FW: as the first 3 characters in the subject and skips the dialog if they are found. By using LCase, it will pick up RE:, Re: or re:.

To check all messages sent from all accounts except your default email account, replace the IF line with this:

If Not Item.SendUsingAccount = "my-default-account@domain.com" Then

To check only for a specific email account, use this:

If Item.SendUsingAccount = "alias-I-don't-use@domain.com" Then

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

On Error Resume Next

If Not Left(LCase(Item.Subject), 3) = "re:" And Not Left(LCase(Item.Subject), 3) = "fw:" Then
      prompt$ = "You sending this from " & Item.SendUsingAccount & ". Are you sure you want to send it?"
       If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Sending Account") = vbNo Then
         Cancel = True
       End If
End If

End Sub

Video tutorial: How to use the ItemSend macros

How to use VBA code samples

To use either of these macros, open the VBA Editor using Alt+F11. Expand Project1.

The macro that checks addresses when you send messages needs to be in ThisOutlookSession.

The macro that forwards mail to a specific address can go into a separate Module. To add a module, right click on Project1 and choose Insert > Module.

Paste the code into the editor.

Change the addresses in the sample code to your own address.

The macro that checks address will run when you send messages.

To create buttons for the forward macro:

In Outlook 2010 or Outlook 2013:
Create a macro button

  1. Go to File, Options, and choose Customize Ribbon.
  2. Add a New Group to the list on the right side then Add the macro to the new group.
  3. Select Macros in Choose Commands from.

In Outlook 2007 and older:

Customize toolbar

  1. Right click in the toolbar area, choose Customize.
  2. Switch to the Commands tab.
  3. Select Macros under Categories.
  4. Drag the macro to anywhere on the Toolbar.

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

64 responses to “Warn before sending messages to the wrong email address”

  1. Sara

    Hi Diane, thanks so much for the vb code samples. awesome logic.

  2. david

    Hi Diane

    Am trying the code to warn before sending, but it is not working (no warning). I do have another rule in place to defer by 1 minute, would this be interfering?

  3. Rizu

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If InStr(LCase(Item.To), "bad@address.com") Then Prompt$ = "You sending this to bad@address.com. Are you sure you want to send it?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then Cancel = True End If End If End Sub

    This code is not working. I am using Outlook 2010

  4. Rizu

    Yes, security is low.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If InStr(LCase(Item.To), "M.Rizwan@domain.com") Then
    Prompt$ = "You sending this to M.Rizwan@domain.com. Are you sure you want to send it?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If
    End Sub

    Please suggest why this is not working ? Thanks a lot in advance

  5. Rizu

    Yes Macro security is Low?

    However I have noticed that Item. To is taken as string instead of mail object. Please can you help on this.

  6. Rizu

    I am not getting any error messages. The Item.To, The To should turn blue in the code right ? its looking black only.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If InStr(LCase(Item.To), "M.Rizwan@domain.com") Then
    Prompt$ = "You sending this to M.Rizwan@domain.com Are you sure you want to send it?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If
    End Sub

  7. Rizu

    I am not getting any error messages. I am using only one Email Id. The Item. To, The To should turn to blue in the code right ? it is black only

  8. Rizu

    Thanks a million !!! its working fine. Just one more clarification if I put a shared INbox email id , then again its not working. Any suggestion on this ? Sorry to disturb you again and again.

  9. Rizu

    LOL!! Yeah its working with the display name. Thanks a lot for your valuable time. I will email you my whole code actually this code is part of it. Please I want your feedback and suggestions.

  10. Alan Chitty

    Hi i have tried this and works great .. how do i change so that it will only alert me when i send messages to addresses outside my domain... i tried *@mydomain but this does not work

    many thanks Alan

  11. Neil Harding

    Great code for checking recipients in Outlook 2003 although I am experiencing a problem with Word not responding after I have sent an email. When I send a mail and confirm that I want to send it using the code, the email goes fine but when I switch back to Word 2003 none of the buttons or menus respond until I click outside of Word and then back in Word. any ideas please?

  12. Ryan

    Hello,

    Iv altered the script a little to fit my need. How ever I'm not sure how to get it to work with emails using mixed case emails. Any feedback on that?

  13. Ryan

    Hey sorry I'm a bit new at this so I'm a little confused. Here is what I have so far.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If InStr((Item.To), "Fake Email(Display name)") Then
    Prompt$ = "This email is for a High Importance Client. Please double check Circuit ID, BPSO, and TX before sending." & Chr(13) & "" & Chr(13) & "EG. 17418CGCG; MTFS-134-L10" & Chr(13) & "" & Chr(13) & " BPSO 4824"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If

    End Sub

    This seems to work if I just put in the display name. Now I have found that when this script is on it fails when i try to send out meeting request and asks to debug.

  14. Ryan

    Hey Diane! I think I have the addressing working for me. Whats really confusing me is its interupting When I send meeting requets now. Its asking for a debug. This is what I have.
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If InStr((Item.To), "Change Control") Then
    Prompt$ = "This email is for a High Importance Client. Please double check Circuit ID, BPSO, and TX before sending." & Chr(13) & "" & Chr(13) & "EG. 17418CGCG; MTFS-134-L10" & Chr(13) & "" & Chr(13) & " BPSO 4824"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If
    End Sub

  15. Ryan

    It says Run-time error 438
    Object doesn't support this property or method

    Then it highlights: If InStr((Item.To), "Change Control") Then

  16. Ryan

    Yeah no change when I alter the name. All other email functions work normaly and the script works but when I send meeting requests it produces debug.

    Is there maybe a diffrent way of writing it to query a specific word?

  17. Nathan

    Hi, the macro to check one specific address before sending works great for me but how can I add a couple more address to check? Thanks!

  18. Nathan

    I meant the macro to check for an email address and not send if it is one of the listed addresses. We just want to warn users before they send to certain people. If the email address is not included then there should be no warning.

    Thanks

  19. Nathan

    The macro is working great now for checking messages as they send, however I get an error when sending meeting invites. "Run-time error '438'": Object doesn't support this property or method.

    The debug option highlights this line:

    If InStr(LCase(Item.To), "test1@test1.com") Then

  20. Nathan

    Hi, the check before sending macro gives me errors whenever I Send or Accept/Cancel meeting invites. Is there a solution to prevent this?

    The error is from Microsoft Visual Basic "Run-time error '438': Object doesn't support this property or method."

    The macro:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    ' use lower case for the address
    ' LCase converts all addresses in the To field to lower case
    If InStr(LCase(Item.To), "bad@address.com") Then
    Prompt$ = "You sending this to bad@address.com. Are you sure you want to send it?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If

    End Sub

  21. Nathan

    Your first reply seems to work (adding If TypeName(Item) = "MailItem").

    I tried the 2nd suggestion but then I get the warning even when the bad address is not used in a meeting invite, so it won't work.

    Adding "If TypeName(Item) = "MailItem"" only checks the address for sending an email, not a calendar invite, but I can live with that. Thanks!!

  22. Nathan

    Hi, I just realized this will not check the addresses in the "CC" field. Is there a way to check both fields at once? If not, what do we include to verify both fields?

  23. Nathan

    Is there a way to catch those email addresses which are stored in the autocomplete list in this format: Firstname Lastname (email@domain.com) or Firstname Lastname

    The macro above will only catch the address if it is by itself, not when the above format is used.

  24. Ian Matheson

    This is really useful, thanks. I'm trying to set it up such that I get a warning when I am sending to (To, CC or BCC) any addresses in a specified external domain. I suspect it is something to do with display name, but can't work out how to do it. Any ideas?

  25. Ian Matheson

    Thanks for the reply.

    It works when I manually type the email address, eg
    john.smith@address.com
    but not when I reply to a mail received from the external domain, where Outlook populates the To: field as:
    Smith, John
    I think this is because it is only validating the display name (Smith, John) and not the actual email address.

    Any suggestions gratefully received!!
    (Also, it would be ideal if all recipients were checked rather than just 'ItemTo'...)

  26. Ian Matheson

    Correction:
    ... but not when I reply to a mail received from the external domain, where Outlook populates the To: field as:
    Smith, John

  27. Ian Matheson

    Sorry for the repetitive posting, but after a bit of research I think I've worked it out.
    The MailItem.To property is used only for display names, so we want to use the Recipients collection as a catch-all. We just change Item.To to Item.Recipient
    and it all seems to work for both new mails and replies, plus checks the To, CC and BCC fields as well:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    On Error Resume Next
    ' use lower case for the address
    ' LCase converts all addresses in the To field to lower case
    If InStr(LCase(Item.Recipient), "bad@address.com") Then
    Prompt$ = "You sending this to bad@address.com. Are you sure you want to send it?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If

    End Sub

  28. Ian Matheson

    Sorry... that doesn't work either! Please feel free to edit/delete my comments into one that actually makes sense!!

  29. Mike Beda

    Hi Diane,

    I wasn't able to make this entirely work for me. It'd work for a new message but not for a reply. I discovered that on replies "Item.Recipients" was blank. Scrounging some other code I managed to change the search term to one that always seems to give the actual email address, so now it works with replies and new messages.

    Thank you for your example. I couldn't have made anything work had I not your code to start with.

    My revised routine is below:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim Recipients As Outlook.Recipients
    Dim i
    Dim prompt As String
    Dim recip As String

    On Error Resume Next

    Set Recipients = Item.Recipients

    For i = Recipients.Count To 1 Step -1
    recip$ = Recipients.Item(i).Address

    If InStr(LCase(recip), "bad@address.com") Then
    prompt$ = "You are sending this to bad@address.com. Are you sure you want to send it?"
    If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    Cancel = True
    End If
    End If

    Next i

    End Sub

    '-Mike Beda

  30. Gordon

    Thanks Diane - I searched high and low before finding this excellent article.

    I also had trouble with the code not working for replies, but following Mike's excellent reworking of your original code, I now have the safety net I needed up and running.

    Thanks both!

  31. ellie

    How can i delay my sent mail for a few minuets when its sent to multiple address but the exempted emails like my coworkers should be sent right away so they can notify me lets say if there's a mistake before its to late ?

    So this is my question when using outlook rules i can or delay all emails but when i exempt some emails from the rules the email gets sent right away even its sent to additional mail address ?????

    can you help perhaps macro or script? i am using outlook 2013 with an exchange account ??

  32. Melissa Ferguson

    I am trying to modify it a little to warn me if mail is sent to specific domains. I was trying to use a wildcard or like statement in the case so that if it is @gmail.com then it will prompt me for something. Is there a way to do that?

  33. John

    As an alternative to VBA, you can use an Add-in called SafeSend that does the same as the code here but with some additional details. You can find it on http://www.slipstick.com/problems/reply-to-all-includes-my-address/

  34. Perry Garrod

    Hi Diane
    Excellent tutorial.
    I have used is for the basis of a Send check routine, which was working initially, but when I had occaision to restart outlook, whilst the VBA all looks good, the macro doesnt run.
    When I select the design button, I get "The macros in this project are disabled..... please refer" which takes me to a Microsoft site full of info, and I dont know where to start.
    Tried enabling all Macros in Trust settings (2012). Didnt make any differnence
    Any thoughts
    Thanks
    Perry

  35. Eric Lau

    The code is great. Thanks a lot. Is it a way to deploy this code using gpo or sccm?
    Thanks.

  36. Alexis

    Hi Diane, I´ve try several times but it doesn´t work, what can I do? Im using this code with VBA and Im following all the steps... please help!

  37. Perry Garrod

    Hi Eric, if you are experiencing the same problem I encountered, in that despite having set full access to run all macros, I still had to alt+f10 (I think) to see if macro loaded. I had password protected it. When the enter password window was displayed I new the macro was loaded and from that point all worked ok. Must be a better way of switching on but couldn't font it, which makes for difficult or impossible company role out

  38. Alexis

    Yes Im putting this on THis Outlooksession and still doesnt work :( what Im doing wrong.

Leave a Reply

If the Post Coment button disappears, press your Tab key.