Forum Discussion

IanaMac's avatar
IanaMac
Brass Contributor
Sep 20, 2023
Solved

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 b...
  • LeonPavesic's avatar
    LeonPavesic
    Sep 20, 2023

    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

Resources