Skip to main content

How to block outgoing emails to a specific address in Outlook?

Author: Xiaoyang Last Modified: 2022-10-19

Generally speaking, Outlook sends emails to all normal email addresses, and can’t block sending emails to a specific email address. But, sometimes, you may need to prevent sending emails to a specific email address in Outlook. In this case, this tutorial will introduce a VBA code for solving this task.


Block outgoing emails to a specific address with VBA code

The following VBA code can do you a favor, please do as this:

1. Launch the Outlook, then, hold down ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Then, double click ThisOutlookSession from the Project-Project1 pane, and then, copy and paste the below code into the blank code window:

VBA code: Block outgoing emails to a specific address

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Updatby ExtendOffice
Dim xMail As Outlook.MailItem
Dim xRecipients As Outlook.Recipients
Dim xContactGroupFound As Boolean
Dim i, n As Long
Dim xRecipient As Outlook.Recipient
Dim xAddress As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
On Error Resume Next
If Item.Class <> olMail Then Exit Sub
Set xMail = Item
xContactGroupFound = True
Do While xContactGroupFound = True
  Set xRecipients = xMail.Recipients
  xContactGroupFound = False
  For i = xRecipients.Count To 1 Step -1
    If xRecipients(i).AddressEntry.DisplayType <> olUser Then
      For n = 1 To xRecipients(i).AddressEntry.Members.Count
        If xRecipients(i).AddressEntry.Members.Item(n).DisplayType = olUser Then
          xMail.Recipients.Add (xRecipients(i).AddressEntry.Members.Item(n).Address)
        Else
          xMail.Recipients.Add (xRecipients(i).AddressEntry.Members.Item(n).Name)
          xContactGroupFound = True
        End If
      Next
      xRecipients(i).Delete
    End If
  Next i
  xRecipients.ResolveAll
Loop
For Each xRecipient In xRecipients
  xAddress = xRecipient.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
  If VBA.Trim(xAddress) = "" Then
    xAddress = xRecipient.Address
  End If
  If xAddress = "yy@addin99.com" Then    'change this email address to your need
    If MsgBox("Do you want to email to " & Chr(34) & xAddress & Chr(34) & "?", vbExclamation + vbYesNo, "Kutools for Outlook") = vbNo Then
      xRecipient.Delete
    End If
  End If
Next
If xMail.Recipients.Count = 0 Then
  Cancel = True
End If
End Sub
Note: In the above code, you should change the email address to your own.

3. Then, save and close this code window. Now, when sending an email, if the specific email address is found in the recipient list, a prompt message will pop out as below screenshot shown. Click No, the specific email address will be deleted immediately.

4. After sending the email, you can check its recipients in the Sent Items folder, the certain email address has been excluded from the recipients, see screenshot:


Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!

🤖 Kutools AI : Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

📨 Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

📁 Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

👍 One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  🕘Show Sender's Time Zone ...

👩🏼‍🤝‍👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Instantly unlock Kutools for Outlook with a single click—permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2
 

 

 

Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations