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 inboxes, 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.

1. Create a Transport rule to block a domain

You can follow below steps to create a Transport rule to block a domain in Exchange Online.

  • Sign in to the Exchange Online admin center using Exchange admin rights.
  • Go to Mail Flow > Rules > Click on + Add a rule.
  • Click on Create a new rule.
Create a Transport rule to block a domain
Create a Transport rule to block a domain

Set rule conditions

Set up the rule conditions as shown below and then click “Next.” In this example, I will be showing how to block the domain “techpress.net” using these specific rule conditions.

  • Name: Block techpress.net domain
  • Apply this rule if: The sender domain is techpress.net [Instead of the domain you can also add an email address here. For example: test@techpress.net].
  • Do the following: Block this message | reject the message and include an explanation.
  • Click Next to proceed.
Create a Transport rule to block a domain
Create a Transport rule to block a domain

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 a Transport rule in Exchange Online, it is initially set to a disabled state by default. To activate the rule, click on the rule and switch it to “Enable
Create a Transport rule to block a domain
Create a Transport rule to block a domain

2. Testing The Transport Rule Created in Previous Step

We’ve created and activated a transport rule in Exchange Online for the organization cloudinfra.net to block emails from the techpress.net domain. Now, let’s proceed to test this rule by sending an email from techpress.net to cloudinfra.net and checking the result.

  • Sender Email address: AlexW@cloudinfra.net
  • Recipient Email Address: GradyA@techpress.net.

You’ll receive the following Non-Delivery Report (NDR) email from postmaster@cloudinfra.net, indicating that a custom mail flow rule created by an admin at cloudinfra.net has blocked your message. The NDR also includes the rejection explanation, which we’ve set in the Transport rule as “Blacklisted domain” You can customize this explanation or leave it blank according to your preferences.

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

Testing The Transport Rule
Testing The Transport Rule

3. Create a Transport rule in Exchange Online to block a Domain with Powershell

To block a domain using Powershell by creating a Transport rule in Exchange Online, you can utilize the New-TransportRule cmdlet. This allows you to set up the necessary rule to block messages from specific domains or senders.

Let’s check the steps:

Install the 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

You can further customize the behavior of the New-TransportRule cmdlet by exploring various additional parameters. One useful parameter is -Priority, which allows you to define the rule’s precedence in relation to other rules.

For instance, if you want to ensure your block domain rule takes precedence, you can assign it a higher priority by setting a lower numerical value, such as -Priority 0. This ensures that it’s processed before other rules in the sequence.

New-TransportRule -Name "Block xyz.com" -Priority 0 -Enabled $true -SenderDomainIs xyz.com -RejectMessageEnhancedStatusCode "5.7.1" -RejectMessageReasonText "Blacklisted Domain"
Create a Transport rule in Exchange Online to block a Domain with Powershell
Create a Transport rule in Exchange Online to block a Domain with Powershell

Conclusion

In this blog post, we’ve explored the simple process of creating a rule in Exchange Online to block a sender’s email address or domain. You can also expedite this process using PowerShell.

While we’ve used a few parameters with the New-TransportRule cmdlet, you can further customize your rules by utilizing additional parameters like -Comments, allowing you to provide helpful comments for each rule. This flexibility enables you to tailor your rule management to meet your organization’s specific requirements.

Leave a Comment