Is it possible to configure Postfix on Plesk to use Smarthost on per domain basis?

Follow

Comments

4 comments

  • Avatar
    Johannes Fuchs

    will there come official support for this? see also https://talk.plesk.com/threads/relay-mail-for-specific-domain.339401/

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

    @Johannes Fuchs
    Plesk development team is already working on implementation of this feature, but there is no ETA yet.

    0
    Comment actions Permalink
  • Avatar
    Faris Raouf

    It is very simple to implement this manually:

    0) Make a backup of /etc/postfix/main.cf in case you make a mess of things

    1) Create /etc/postfix/relay_map

    2) Add the following content to relay_map
    @domain.tld [smarthost.full.address.tld]:PORT

    Where domain.tld is a domain for which you want to route outgoing email via smarthost.full.address.tld (all other mail going via your server as normal). And where PORT is whatever port your smarthost wants you to connect to, for example 25 or 587.

    You MUST include the [square brackets] around the smarthost address. They are not there for decoration. If you don't include them, Postfix will not connect to the A record of the smarthost address. Instead it will do an MX lookup on the smarthost address and connect to the IP pointed to by that record. And that's probably not what you want (although it might be). 

    3) run the following command:
    postmap /etc/postfix/relay_map
    This will create a hashed version of your relay_map (ends with .db) which is what Postfix actually reads (next step)

    4) Add the following line to the bottom of  /etc/postfix/main.cf
    sender_dependent_relayhost_maps = hash:/etc/postfix/relay_map

    Do NOT add the .db ending to relay_map on this line. By specifying "hash:" Postfix knows to look at the .db version of the file and not the plain text version.


    5) Reload Postfix with the following command:
    systemctl reload postfix

    Now, all email will go as normal via the Plesk box, except for those domains specified in relay_map, for which email will be sent via the smarthost specified.

    if you want to update the domains and smarthosts, edit relay_map file and then re-run the postmap command (Step 3)

    If you encounter errors, simply remove the line you added to main.cf :
    sender_dependent_relayhost_maps = hash:/etc/postfix/relay_map
    and then reload postfix (step 5), at which you will be back to how you started.

    WARNING: When using a smarthost like this, you must make sure your SPF records for the domain in question reflect the fact that you are sending from an IP other than one belonging to your Plesk box. If you don't, your messages may not be accepted by the final destination mailserver.   

    WARNING: As has been pointed out in the KB article, the configuration change you make to main.cf may be removed without warning during a Plesk update. Always check after updating. 

    NOTE: This is the simplest version of this configuration. It can be used when the smarthost doesn't need a username and password for authentication (e.g. when IP-based authentication is used instead). If you need to specify a username and password, a bit more is required. I'll let someone else offer an example if need be.

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello Faris Raouf

    Thank you for the comment it may be useful for other Pleskians.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request