Forum Discussion
Limit the number domains in recipient list on mail
Hi all
We have an issue where one of our support teams using a shared mailbox were a user inadvertently sent an e mail to an incorrect client due to preemptive listing of e mail address's
I have been tasked with finding a solution where users can only add 1 domain plus our internal domains.
I would prefer to find a solution that resides on the exchange side rather than the client side, i am sure that we are not the only organisation that has this requirement!!!
Many thanks for any suggestions
Hi IanaMac,
yes, you need to add domains manually if you are using GUI, but you can add domains automatically to the list using a PowerShell script to read the list of domains from a file and then add them to the list of blocked domains in the transport rule or mail flow rule.Here is an example of a PowerShell script to add domains automatically to the list of blocked domains in a transport rule from the .txt. file:
# Import the Exchange module Import-Module Exchange # Get the transport rule $transportRule = Get-TransportRule "Block messages to external domains" # Add the domains to the list of blocked domains foreach ($domain in Get-Content "Domains.txt") { $transportRule.Conditions.RecipientDomain.BlockedDomains.Add($domain) } # Set the transport rule Set-TransportRule $transportRule
- To use this script, you would first need to create a text file called Domains.txt that contains the list of domains that you want to block.- Once you have created the text file, you can run the PowerShell script to add the domains to the list of blocked domains in the transport rule.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
7 Replies
- LeonPavesicSilver Contributor
Hi IanaMac,
There are a couple of ways to limit the number of domains in the recipient list on mail in Exchange:
Use a mail flow rule. A mail flow rule is a rule that can be applied to all outgoing messages in your Exchange organization. To create a mail flow rule to limit the number of domains in the recipient list, follow these steps:
- Open the Exchange admin center.
- Go to Mail flow > Rules.
- Click New rule.
- Give the rule a name and description.
- Under Apply this rule if, select the Any message condition.
- Under Do the following, select the Block the message action.
- Click Add condition.
- Under Select a condition, select the Recipient domain condition.
- Under Configure the condition, select the Matches any of the following patterns option and enter the following patterns:
*.example.com *.example.net
- Click OK.
- Click Save.
Use a transport rule. A transport rule is similar to a mail flow rule, but it is processed before mail flow rules. To create a transport rule to limit the number of domains in the recipient list, follow these steps:
- Open the Exchange admin center.
- Go to Organization > Transport rules.
- Click New rule.
- Give the rule a name and description.
- Under Apply this rule if, select the Any message condition.
- Under Do the following, select the Reject the message action.
- Click Add condition.
- Under Select a condition, select the Recipient domain condition.
- Under Configure the condition, select the Matches any of the following patterns option and enter the following patterns:
*.example.com *.example.net
- Click OK.
- Click Save.
Here are some additional links to information about limiting the number of domains in the recipient list on mail in Exchange:
- Limit the number of domains in recipient list for outgoing mail in Exchange Server: https://learn.microsoft.com/en-us/office365/servicedescriptions/exchange-online-protection-service-description/exchange-online-protection-limits
- How to limit the number of domains in the recipient list for outgoing mail in Exchange Online: https://learn.microsoft.com/en-us/office365/servicedescriptions/exchange-online-protection-service-description/exchange-online-protection-limits
- Third-party solutions for limiting the number of domains in the recipient list on mail in Exchange: https://learn.microsoft.com/en-us/exchange/mail-flow/mail-routing/recipient-resolution?view=exchserver-2019
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
- Victor_IvanidzeBronze Contributor
Hi LeonPavesic,
could you please tell me why I don't see "Transport rules" under "Organization"?
There is only one subitem under "Organization": "Sharing".
Thanks.
- LeonPavesicSilver Contributor
Hi Victor_Ivanidze,
thanks for your update. you are right, I wrote it wrong.
You can find Transport rules under Mail flow --> Rules.
(and not under Organization)Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
- IanaMacBrass ContributorHi Leon
thanks for this the transport and mailflow rules mean that we would have to add 100 of domains to the list...
I will look at the documentation now- LeonPavesicSilver Contributor
Hi IanaMac,
yes, you need to add domains manually if you are using GUI, but you can add domains automatically to the list using a PowerShell script to read the list of domains from a file and then add them to the list of blocked domains in the transport rule or mail flow rule.Here is an example of a PowerShell script to add domains automatically to the list of blocked domains in a transport rule from the .txt. file:
# Import the Exchange module Import-Module Exchange # Get the transport rule $transportRule = Get-TransportRule "Block messages to external domains" # Add the domains to the list of blocked domains foreach ($domain in Get-Content "Domains.txt") { $transportRule.Conditions.RecipientDomain.BlockedDomains.Add($domain) } # Set the transport rule Set-TransportRule $transportRule
- To use this script, you would first need to create a text file called Domains.txt that contains the list of domains that you want to block.- Once you have created the text file, you can run the PowerShell script to add the domains to the list of blocked domains in the transport rule.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic