How to block an email address or domain in Exchange Online

Email communication is an integral part of today’s business world, and it’s hard to imagine our work lives without it. However, with the benefits of email come a few drawbacks as well. One of them is spam emails or unwanted emails from senders or domains that we don’t want to hear from.

These unwanted emails can clog up our inbox, waste our time, and decrease our productivity. Fortunately, Exchange Online Protection offers a solution to this problem by allowing administrators to create Rules in Exchange Online to block specific email addresses or domains.

Blocking an email address or domain using Exchange Online is a straightforward process that can be done in a few simple steps. By doing so, you can ensure that you don’t receive any more unwanted emails from the sender or domain that you have blocked.

In this blog post, I will show you how to block an email address or domain using Exchange Online. I will guide you through the process step by step, and by the end of this post, you will be able to block unwanted emails from any sender or domain you choose.

Steps to create a Transport rule for blocking a domain

Here are the steps to create a Transport rule for blocking a domain in your Exchange Online environment. Transport rules allow you to set conditions and actions for messages that pass through your organization’s email system.

Blocking a domain is a common use case for transport rules, as it can help protect your organization from spam, phishing, and other unwanted messages. With these easy-to-follow steps, you’ll be able to create a Transport rule that blocks messages from any domain you choose.

  • Go to Mail Flow > Rules > Click on + Add a rule.
  • Click on Create a new rule.
Steps to create a Transport rule for blocking a domain

Set rule conditions

Set below rule conditions and click Next. We would be blocking an example domain techpress.net by configuring below rule conditions.

  • Name: Block techpress.net domain
  • Apply this rule if: The sender domain is techpress.net [Instead of domain you can also add an email address here. For example: test@techpress.net].
  • Do the following: Block this message and reject the message and include an explanation.
  • Click Next to proceed.
Set rule conditions Block Domain in Exchange online

Set rule settings

  • Set below rule settings and Click on Next.
    • Rule mode: Enforce.
    • Keep the rest of the settings as default.
  • Review and click on Finish to create the rule.
  • When you create any Transport rule in Exchange Online, by default its created in disabled state. Click on the Rule and toggle the switch to Enable.
Set rule settings / Enable Rule Block Domain in Exchange online

Testing the block domain transport rule

We have created and Enabled a transport rule in Exchange Online of organization cloudinfra.net which blocks the domain techpress.net. Now, let’s send a test email from techpress.net to cloudinfra.net to see what results we get.

Sending a test email to AlexW@cloudinfra.net from GradyA@techpress.net.

Received below NDR email from postmaster@cloudinfra.net that there is A custom mail flow rule created by an admin at cloudinfra.net has blocked your message. Then you also see your reject explanation set in the Transport rule. We provided the explanation of rejection as Blacklisted domain. You can provide any explanation you want or keep it blank as well.

Message rejection Status code is Status code: 550 5.7.1_ETR.

550 5.7.1 TRANSPORT.RULES.RejectMessage; the message was rejected by organization policy

Postmaster NDR email after testing domain block transport rule

Create a rule in Exchange Online for blocking a domain using Powershell

You can also use Powershell to block a domain by creating a Transport rule in Exchange Online. The cmdlet which we will use is New-TransportRule.

First you need to Install Exchange Online powershell module if not installed already. Then you need to connect to Exchange online and use the cmdlet’s to create a new Transport rule in Exchange Online.

Install Exchange Online Powershell module

Install-Module ExchangeOnlineManagement

Connect to Exchange Online

Connect-ExchangeOnline

Create a new Transport rule to block xyz.com

New-TransportRule -Name "Block xyz.com" -SenderDomainIs "xyz.com" -RejectMessageEnhancedStatusCode "5.7.1" -RejectMessageReasonText "Blacklisted Domain" -Enabled $true

There are a lot of other parameters as well which you can explore and use it with New-TransportRule cmdlet. For example you can add -priority parameter to set the priority for this rule. For example:

New-TransportRule -Name "Block xyz.com" -Priority 0 -Enabled $true -SenderDomainIs xyz.com -RejectMessageEnhancedStatusCode "5.7.1" -RejectMessageReasonText "Blacklisted Domain"

For complete list of parameters which you can use with New-Transportrule cmdlet, Please refer to New-TransportRule reference page.

Create a new Transport rule to block a domain using Powershell in Exchange Online

Conclusion

In this blog post, we have seen how you can easily create a rule in Exchange online to block a sender’s email address or domain. You can even use Powershell for this to speed up the rule creation. I have used only couple of parameters with New-Transportrule cmdlet but you can add other parameters as well like -Comments and provide a useful comment for the rule.

READ NEXT