Recipient filters work differently in MS Exchange 2013 compared to previous version. As you can see from the session below the reject is done after the DATA is processed.
mail from:<me@example.com> 250 2.1.0 Sender OK rcpt to:<nouser@domain.com> 250 2.1.5 Recipient OK data 354 Start mail input; end with Write some Text Here. . 550 5.1.1 User unknown
The below example shows you how to setup a recipient filter for MS Exchange to reject unknown users.
This solution is for Exchange Servers 2013 and using the anti-spam agent for exchange. This is an available feature in the Edge Transport Server. However if you don't have Edge Transport Server it is possible to install the anti-spam agent in the Hub Transport Server.
First let's verify the Anti-Spam Functionality is enabled
Get-TransportAgent
$prompt:ExchangeInstallPath\Scripts\Install-AntiSpamAgents.ps1If is available but disabled you can enable it by the below command
Enable-TransportAgent "Recipient Filter Agent"
Restart the Exchange Transport service after making the above changes.
The next step is to ensure your accepted domains are using the AddressBook for checking for valid recipients. By default, this should be enabled when you set up Exchange as an authoritative Mailbox Server for your domain.
Get-AcceptedDomain | Format-List Name,AddressBookEnabled
Set-AcceptedDomain <name of accepted domain> -AddressBookEnabled $true
Get-AcceptedDomain | Set-AcceptedDomain -AddressBookEnabled $true
Get-AcceptedDomain | ? {$_.AddressBookEnabled -ne "True"} | Set-AcceptedDomain -AddressBookEnabled $true
Now you should have Recipient Filter enabled on your Mailbox Server and AddressBook enabled on you domain. But, if you test this now, it probably still won't work. That's because validation is still disabled.
Get-RecipientFilterConfig | FL Enabled,RecipientValidationEnabled
Enabled : True RecipientValidationEnabled : False
Set-RecipientFilterConfig -RecipientValidationEnabled $true
If we now test we should see a reject on the unknown user, which can be tested using telnet
telnet yourExchangeServerHost 2525
mail from:<me@example.com> 250 2.1.0 Sender OK rcpt to:<real-user@domain.com> 250 2.1.5 Recipient OK rcpt to:<invaliduser@domain.com> 550 5.1.1 Address Unknown
Set-SenderFilterConfig -Enabled $false Set-SenderIDConfig -Enabled $false Set-ContentFilterConfig -Enabled $false Set-SenderReputationConfig -Enabled $falseFollowing commands will prompt for confirmation. Therefore, run them one at time.
Disable-TransportAgent "Sender Filter Agent" Disable-TransportAgent "Sender ID Agent" Disable-TransportAgent "Content Filter Agent" Disable-TransportAgent "Protocol Analysis Agent"