Sometimes, important email can come to your users from external systems. Outlook for Web can sometimes block the images from these emails, requiring the user to add the email address to their safe senders list in order for the images to display properly. Microsoft does not provide a way to centrally manage this list from Exchange Online, so you must use an automated process if you want to add certain addresses to this list for all users.
This blog will detail a quick PowerShell script that can loop through each mailbox and add an email address to the safe senders list.
You will need the Exchange Online PowerShell module installed on your computer. If you do not have it installed, you can install it by opening PowerShell as an administrator and running:
install-module ExchangeOnlineManagement
How to Add External Email Addresses to Safe Senders List in Outlook for Web Using PowerShell
To initially add an address to the safe senders list, you really only need three lines of PowerShell.
connect-exchangeonline $mbxs = (get-mailbox -resultsize unlimited -recipienttypedetails usermailbox).userprincipalname $mbxs | set-mailboxjunkemailconfiguration -TrustedRecipientsAndDomains @{Add="<email address>"} -TrustedSendersAndDomains @{Add="<email address>"}
Note that depending on how many mailboxes are in your environment, this may take a while to run. This will only apply the safe sender entry to user mailboxes. If you want to include shared mailboxes, change the recipienttypedetails parameter to usermailbox,sharedmailbox.
Automate the Maintenance of Safe Senders List in Exchange Online with PowerShell Script
Your users can self-maintain this list, which means that some are likely to remove the entries you have added. This will also catch mailboxes that have been created after you initially added an entry to safe senders.
To maintain the safe senders list with your entries, run the following PowerShell script as a scheduled task.
connect-exchangeonline $mbxs = get-mailbox -resultsize unlimited -recipienttypedetails usermailbox | select userprincipalname $missing_entry = $mbxs | ForEach {get-mailboxjunkemailconfiguration -identity $_.UserPrincipalName} | where-object -filterscript {$_.TrustedSendersAndDomains -notcontains "<email address>"} ForEach ($mbx in $missing_entry) { $mbx | set-mailboxjunkemailconfiguration -TrustedRecipientsAndDomains @{Add="<email address>"} -TrustedSendersAndDomains @{Add="<email address>"} }
Note that depending on how many mailboxes are in your environment, this may take a while to run. This will only apply the safe sender entry to user mailboxes. If you want to include shared mailboxes, change the recipienttypedetails parameter to usermailbox,sharedmailbox.
Final Thoughts
Maintaining a safe senders list so that emails properly display can be difficult sense Microsoft does not provide a central way of managing this list from Exchange Online. With these simple PowerShell scripts, you can add entries so that your users’ email displays properly.
Disclaimer
All content provided on this blog is for information purposes only. Windows Management Experts, Inc. makes no representation as to the accuracy or completeness of any information on this site. Windows Management Experts, Inc. will not be liable for any errors or omissions in this information nor for the availability of this information. It is highly recommended that you consult one of our technical consultants, should you need any further assistance.
Windows Management Experts
Now A Microsoft Solutions Partner for:
✓ Data & AI
✓ Digital and App Innovation
✓ Infrastructure
✓ Security
The Solutions Partner badge highlights WME’s excellence and commitment. Microsoft’s thorough evaluation ensures we’re skilled, deliver successful projects, and prioritize security over everything. This positions WME in a global tech community, ready to innovate on the cloud for your evolving business needs.
Contact us: sales@winmgmtexperts.com