Introduction
Managing junk email and safe sender settings is crucial for ensuring important emails don’t get lost in the spam folder. In Microsoft 365 Exchange Online, PowerShell can be a powerful tool to manage these settings. This guide walks you through how to fetch and update the Safe Senders list for a user using PowerShell. This tutorial is especially helpful for Microsoft 365 administrators who want to automate and manage user preferences.
Prerequisites
Before running these scripts, ensure you are connected to Exchange Online PowerShell. You can connect using the following command:
Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com
Script 1: Export Safe Senders List
This script extracts the Safe Sender list (also known as Trusted Senders and Domains) for a user.
PowerShell Script:
Get-MailboxJunkEmailConfiguration -ResultSize Unlimited -Identity "UserEmailAddress" | Select TrustedSendersAndDomains | Export-CSV "C:\Users\Desktop\Information.csv"
Explanation:
– Get-MailboxJunkEmailConfiguration : This command fetches junk email settings for a mailbox.
– ResultSize Unlimited : Ensures all results are retrieved without any limit.
– Identity “UserEmailAddress” : Replace this with the user’s actual email address.
– Select TrustedSendersAndDomains : Extracts only the Safe Sender list.
– Export-CSV : Saves the output to a CSV file for easy viewing.
Script 2: Add Safe Sender Email
Use this script to add a specific email address to a user’s Safe Senders list.
PowerShell Script:
Set-MailboxJunkEmailConfiguration -Identity "UserEmailAddress" -TrustedSendersAndDomains @{Add = "EmailAddress - Which You want to add"}
Explanation:
– Set-MailboxJunkEmailConfiguration : Modifies the junk email settings for the mailbox.
– Identity “UserEmailAddress” : Specify the user’s email address.
– TrustedSendersAndDomains @{Add = “…”} : Adds the specified email to the Safe Senders list.
Output Examples
For the first script, the exported CSV file (Information.csv) will look like this:
TrustedSendersAndDomains
Output Examples
For the first script, the exported CSV file (Information.csv) will look like this:
TrustedSendersAndDomains
someone@example.com
support@company.com
For the second script, there’s no visible output, but you can verify it by re-running the first script.