This is an old revision of the document!


Let postfix only accept mails for addresses in Exchange

Problem:

  • I use postfix as a backup for my Exchange. I want postfix to only accept mail for recipients which exist in Exchange.

Requirements:

  • I assume you followed my first tutorial here
  • Existing postfix installation (mine is on debian)
  • Existing Exchange (2010 or 2013) installation

  • Create the following PowerShell script on your Exchange server:
  • $ExcludeUsers = @("Administrator", "user1")
    
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    
    # Get all valid recipients, excludes DiscoverySearchMailbox and every user alias included in ExcludeUsers
    $ValidRecipients = Get-Mailbox | where {$_.Alias -NotLike "DiscoverySearchMailbox*"} | where {$_.Alias -NotIn $ExcludeUsers}
    foreach ($Address in $ValidRecipients.EmailAddresses)
    {[string]::Format("{0}`tOK", $Address.AddressString)}
  • Run the script and save the output to a file like this:
    ./script.ps > output.txt

  • Connect to yout server running postfix
  • Upload the scriptoutput to /etc/postfix/relay_recipients
  • Add the following lines to your /etc/postfix/main.cf:
  • relay_recipient_maps = hash:/etc/postfix/relay_recipients
    show_user_unknown_table_name = no
  • Reload or restart postfix
  • tutorial/mail/postfixrelay.1376778663.txt.gz
  • Last modified: 2018-06-03 14:10
  • (external edit)