Managing Inbox Block/Allow Lists for All Mailboxes in Exchange Online Using PowerShell

Managing Inbox Block/Allow Lists for All Mailboxes in Exchange Online Using PowerShell

As an administrator, managing mailbox settings for hundreds or thousands of users in Exchange Online can be daunting. There are multiple ways for making incoming email traffic more secure. Besides the tenant features, you may want to manage inbox level block or allow lists. Doing this manually is time-consuming, but with PowerShell, you can automate this process efficiently.

In this guide, we’ll show you how to add a domain to all mailboxes’ inbox block or allow lists using PowerShell. We’ll cover both scenarios: allowing and blocking a domain. This configuration can help to remove warnings like the following:

“Some content in this message has been blocked because the sender isn’t in your Safe senders list.”

Step 1: Connect to Exchange Online

Open PowerShell and run the following commands to connect to Exchange Online:

# Install the Exchange Online Management module if not installed
Install-Module -Name ExchangeOnlineManagement

# Import the module
Import-Module ExchangeOnlineManagement

# Connect to Exchange Online
Connect-ExchangeOnline

Step 2: Adding a Domain to the Allow List

To allow emails from a specific domain (e.g., example.com) for all users, use the following script:

$All = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited; $All | foreach {Set-MailboxJunkEmailConfiguration $_.Name -TrustedSendersAndDomains @{Add="example.com"}}

Step 3: Adding a Domain to the Block List

To block emails from a specific domain (e.g., spamdomain.com) for all users, use this script:

$All = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited; $All | foreach {Set-MailboxJunkEmailConfiguration $_.Name -BlockedSendersAndDomains @{Add="spamdomain.com"}}

Step 4: Verify Changes

To ensure the changes were applied successfully, you can check a specific mailbox’s Junk Email configuration:

Get-MailboxJunkEmailConfiguration -Identity user@yourdomain.com

Notes

  • Changes may take some time to propagate depending on the size of your tenant.
  • Be cautious when adding domains to block lists as it may inadvertently impact legitimate emails.
  • Regularly review the allow and block lists to keep them updated.

Reference doc: Set-MailboxJunkEmailConfiguration (ExchangePowerShell) | Microsoft Learn

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply