Graph and PowerShell Blog | About | Links
Postfix Receive and Forward
27-Jun-24

Postfix Articles
  • Adding a Postfix server for relay to O365
  • Advanced Postfix configuration
  • Postfix routing by filtering
  • Postfix Receive and Forward

  • Up to now, my focus with Postfix has been on relaying mails from the LAN out to Office365. Everything I've thrown at it, Postfix has been able to handle, but when it comes to Postfix receiving there is very little information and the proposed solutions tend to be complicated, like running 2 versions of Postfix on the same server.

    One thing I wanted to setup was an outbound connector from Office365, this would allow an Outlook user to send an email to our legacy Domino mail servers.

    To start off, create the connector in Office365 (EAC - Mail flow - Connectors). We will make things simple and use the same routing URL as our 3rd party certificate, so relay.domain.com. We already added a DNS A record for this previously, but you may need to tweak your firewall rule as all mails will come in via *.protection.office365.com.

    ↑ Configure the O365 Outbound Connector.


    A validation mail will be sent when you setup the connector, so if it fails you may need to check the firewall rule.

    ↑ Validation mail showing a successful setup.


    So now the email can route to your Postfix server, but the hard part is still to come. We don't want Postfix to host the received emails, we want to route them to a Domino server, or in this test, an IIS 6.0 SMTP Server.

    It took me a few hours of testing before I stumbled upon a great article explaining how to forward the mail. You need to setup the following in your main.cf file:

    # Incoming Mails (/etc/postfix/main.cf)
    # =====================================
    mydestination = localhost
    transport_maps = hash:/etc/postfix/transport
    relay_domains = hash:/etc/postfix/relay

    Create the transport and relay files like so:
    /etc/postfix/transport
    ======================
    relay.doamin.com relay:[iis_server.domain.local]:25

    /etc/postfix/relay
    ==================
    relay.domain.com ok

    As with any hashed file we then need to run postmap, now and any time we make changes to those files:

    postmap /etc/postfix/transport
    postmap /etc/postfix/relay
    service postfix reload

    I was worried when I added this config that it would interfere with the routing for outgoing relayed mails, but it didn't affect them at all.

    After Postfix was setup it was time to move on to the IIS SMTP Server. Create a virtual domain for relay.domain.com (Alias) so it won't reject the relayed email from Postfix. The email will go to a default folder, C:\inetpub\mailroot\Drop, and is kept in mail.eml format.

    ↑ We can see some emails have arrived in our IIS SMTP Server.


    We can see the routing of this mail by looking at the message headers:

    ↑ Mail routed from O365, to Postfix, to IIS SMTP Server.