Cry Exchange 2010 How To...
How to add sender exceptions to content filtering (whitelisting senders)
Contents:
- Preamble
- Whitelisting a single sender
- Listing whitelisted senders
- Gotchas when whitelisting senders
- Adding a sender to the whitelist
- Whitelisting sender domains
Preamble
We had a situation where a company was sending us emails and they were bouncing with:
550 5.7.1. Message rejected as spam by Content Filtering
we needed to receive these messages and the sending company was unable (or unwilling) to invest the time to identify why the messages were being blocked. In this instance it wasn't viable to whitelist their sending email server, so the approach I wanted was to whitelist the sender's email address.
Exchange Management Console does not allow you to do this. The only options it provides (Exchange Management Console → Microsoft Exchange On-Premises → Organizational Configuration → Hub Transport → Anti-Spam → Content Filtering) is to allow through emails containing certain words or phrases. This was a little too vague for me.
Whitelisting a single sender
Fortunately you can whitelist a sender - but you can only do this using the Exchange Management Shell.
The cmdlet to do this is:
Set-ContentFilterConfig -BypassedSenders email-address
so to whiltelist the email address "noreply@example.com" would be:
Set-ContentFilterConfig -BypassedSenders noreply@example.com
for example:
[PS] C\>Set-ContentFilterConfig -BypassedSenders noreply@example.com
[PS] C:\>
Any emails that claim to come from that sender will now bypass content filtering. So be sure that it isn't an email address that spammers are likely to use!
That's it ... except not quite. In practice don't do this - why? see "Gotcha when whitelisting senders" below.
Listing whitelisted senders
To see which email addresses you have whitelisted in this way use:
(Get-ContentFilterConfig).BypassedSenders
for example:
[PS] C:\>(Get-ContentFilterConfig).BypassedSenders
Creating a new session for implicit remoting of "Get-ContentFilteringConfig" command...
Length Local Domain IsValidAddress
------ ----- ------ --------------
19 noreply example.com True
[PS] C:\>
Gotchas when whitelisting senders
Something to be aware of when using "Set-ContentFilterConfig
-BypassedSenders
" is that each time you use it you are overwriting
the previous list. So:
[PS] C\>Set-ContentFilterConfig -BypassedSenders noreply@example.com
[PS] C\>Set-ContentFilterConfig -BypassedSenders brian@example.com
[PS] C:\>
Will only whitelist "brian@example.com" and not "noreply@example.com"!
To whitelist multiple email addresses you have to list each one on the same line, separated by a comma for example:
[PS] C\>Set-ContentFilterConfig -BypassedSenders noreply@example.com, brian@example.com
[PS] C:\>
The other thing to be aware of is that (whilst it might seem obvious) remember that this works on the "sender" email, which might not be the same as the "from" email address. So if an email is sent "From noreply@example.com on behalf of brian@example.com" then the sender is "noreply@example.com" and the from address is "brian@example.com", so whitelisting would require the "noreply@example.com" email address to be listed.
Adding a sender to the whitelist
If you have a list of senders to maintain then listing then all
each time you call Set-ContentFilterConfig
may not be convenient.
But what you can do is to extract a list, add to that list and then
use that to reset the list of whitelisted emails. Thus:
$whitelist = (Get-ContentFilterConfig).BypassedSenders
$whitelist.add("email-address")
Set-ContentFilterConfig -BypassedSenders $whitelist
For example:
[PS] C:>$whitelist=(Get-ContentFilterConfig).BypassedSenders
[PS] C:>$whitelist.add("noreply@example")
[PS] C:>Set-ContentFilterConfig -BypassedSenders $whitelist
Whitelisting sender domains
You can also whitelist entire email domains:
Set-ContentFilterConfig -BypassedSenderDomains "example.com"
although again the better way to do this would be:
$whitelist = (Get-ContentFilterConfig).BypassedSenderDomains
$whitelist.add("email-domain")
Set-ContentFilterConfig -BypassedSenderDomains $whitelist
and you can see the whitelisted domains using:
(Get-ContentFilterConfig).BypassedSenderDomains
These notes have been tested with Exchange Server 2010.
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.