Applicable to:
- Plesk for Linux
Question
Is it possible to configure Postfix on Plesk to use the Smarthost on a per-domain basis?
Answer
Such functionality is not implemented yet, you can vote for it on Plesk UserVoice:
The top-ranked suggestions are likely to be included in the next versions of Plesk.
Note: it is possible to configure Postfix to use Smarthost per domain basis via Postfix configuration. Such customizations were not tested properly and are not officially supported by Plesk, so perform it at your own risk.
-
Connect to the server via SSH.
-
Back up Postfix configuration file:
# cp /etc/postfix/main.cf /etc/postfix/main.cf.bk
-
Create the file
/etc/postfix/relay_map
# touch /etc/postfix/relay_map
-
Edit
/etc/postfix/relay_map
, adding the following line:Note: substitute
example.com
with the domain which should use the smarthost,smarthost.com
with the Smarthost address. 25 is the outgoing mail port (can be altered, as well).CONFIG_TEXT: @example.com [smarthost.com]:25
-
Run the following command to create a hashed version of relay map:
# postmap /etc/postfix/relay_map
-
Edit
/etc/postfix/main.cf
, adding the following line:CONFIG_TEXT: sender_dependent_relayhost_maps = hash:/etc/postfix/relay_map
-
Reload Postfix configuration:
# systemctl reload postfix
Refer to the Postfix official documentation for more information.
Note: Any customization made in Postfix configuration can be overwritten by Plesk Update (for example, in case of a bug fix, when configuration files are updates), Plesk Upgrade or by the mchk
utility, which resets default mail server configuration.
Comments
4 comments
will there come official support for this? see also https://talk.plesk.com/threads/relay-mail-for-specific-domain.339401/
@Johannes Fuchs
Plesk development team is already working on implementation of this feature, but there is no ETA yet.
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.
Hello Faris Raouf
Thank you for the comment it may be useful for other Pleskians.
Please sign in to leave a comment.