Problem
How to setup a Mail Relay for a subscription in a Plesk Control Panel?
How to setup outMail for a number of subscriptions on a Plesk Control Panel?
How to setup a SMTP Mail Relay on a Plesk Control Panel?
Solution
Follow the guide below to configure a domain/subsciption to sending emails using outMail as a Internet Mail Relay instead of the default SMTP gateway already setup on the Plesk.
This article already assumes your Plesk system is able to send emails externally and that you are already have a terminal/shell connection to your server with the necessary access rights to manage and administor postfix.
In this example we will assume you have a subscription setup on the Plesk with a domain called example.com and instead of emails going the default way you want emails from example.com to go via outMail SMTP Email relay service. It is further assumed you have already signed up for a outMail service and you have the assigned outMail server and SMTP credentials.
Step 1 - Gather your outMail Credentials
You will need your outMail credentials in order to configure postfix in the Plesk. ou can find those details in the Portal as well as your original welcome email.
Example of credenitals
outMail Server | outMail Username | outMail Password |
---|---|---|
mxXXXXXX.smtp-engine.com | example-username | example-password |
Step 2 - Create DNS CNAME records
Assuming that you will want multiple outMail accounts to assigned to multiple subscription respectively you will also need to create DNS CNAME for each assigned outMail server.
Example of CNAMES
Host | CNAME |
---|---|
example-com-outmail.mydomain.com | CNAME mxXXXXXX.smtp-engine.com |
Step 3 - Create a postfix relay file
With shell/console access to the Plesk server you need to create a password file for postfix to use. Create a file called /etc/postfix/relay_passwd and add the following lines to that file.[example-com-outmail.mydomain.com]:25 example-username:example-password
where example-username and example-password are the (case-sensitive) information provided when you set up your account.
The format of the /etc/postfix/relay_passwd file is as follows
[CNAME_HOSTNAME]:OUTMAILPORT OUTMAILUSERNAME:OUTMAILPASSWORD
Step 4 - Create a postfix relay map file
Now we need to create a postfix map file for postfix to use. Create a file called /etc/postfix/relay_map and add the following lines to that file
@example.com [example-com-outmail.mydomain.com]:25
where [example-com-outmail.mydomain.com]:25 must match what you entered in the relay_passwd file and must be the same as the CNAME created.
The format of the /etc/postfix/relay_map file is as follows
@example.com [CNAME_HOSTNAME]:OUTMAILPORT
Step 5 - postmap
We now need to create lookup databases from those two files using postmap.
postmap /etc/postfix/relay_map postmap /etc/postfix/relay_passwd
Step 6 - Make changes to the posttix configuration
To enable postfix to use the outMail service for those domains we type the following.
postconf -e smtp_sasl_auth_enable=yes postconf -e sender_dependent_relayhost_maps=hash:/etc/postfix/relay_map postconf -e smtp_sasl_password_maps=hash:/etc/postfix/relay_passwd postconf -e smtp_sasl_security_options=noanonymous postconf -e smtp_sasl_security_options=$smtp_sasl_security_options
Step 7 - restart postfix
For the above changes to take effect the postfix service will need restarting (service postfix restart).
service postfix restart
Adding a second domain
You now have a second domain (acme.com) from a different subscription that also wants to send out using outMail, but with different outMail credentials. In addition you want to send to outMail using a different SMTP port (In this example 2525).
Example of credenitals
outMail Server | outMail Username | outMail Password |
---|---|---|
mxXXXXXX.smtp-engine.com | example-username | example-password |
mxXXXXXX.smtp-engine.com | acme-username | acme-password |
Step 1 - Add another CNAME
Create DNS CNAME for each of the assigned outMail services.
Note: Even if the assigned outMail server is the same as previous entries still create the additional CNAME. Reason for this is the CNAME is used in the /etc/postfix/relay_map and /etc/postfix/relay_passwd files to link the subscription to the respective outMail service and credentials.
Updated CNAMES
Host | CNAME |
---|---|
example-com-outmail.mydomain.com | CNAME mxXXXXXX.smtp-engine.com |
acme-com-outmail.mydomain.com | CNAME mxXXXXXX.smtp-engine.com |
Step 2 - Modify the postfix relay file
With shell/console access to the Plesk server you need to edit the existing password file (/etc/postfix/relay_passwd).
[example-com-outmail.mydomain.com]:25 example-username:example-password [acme-com-outmail.mydomain.com]:2525 acme-username:acme-password
where acme-username and acme-password are the (case-sensitive) information provided when you set up your outMail service for acme.com.
Step 3 - Modify the postfix relay map file
Now we need to edit postfix map file (/etc/postfix/relay_map).
@example.com [example-com-outmail.mydomain.com]:25 @acme.com [acme-com-outmail.mydomain.com]:2525
where [acme-com-outmail.mydomain.com]:2525 must match what you entered in the relay_passwd file.
Step 4 - postmap
We now need to re-create lookup databases from those two files using postmap.
postmap /etc/postfix/relay_map postmap /etc/postfix/relay_passwd
Step 5 - restart postfix
For the above changes to take effect the postfix service will need restarting (service postfix restart).
service postfix restart
Additional Steps
Below are some additional steps you might want to consider.
SPF Support
As you domain is now sending out bound emails via outMail you should add to your existing SPF record the outMail SPF record.
More information on this can be found in this KB Article -> How to create a Sender Policy Framework (SPF) Record to Authorise outMail Servers to send out your Email
DKIM Support
outMail supports the DKIM of signing of emails.
If you want to DKIM sign emails then a useful guide can be found in this KB Article -> How do I enable DKIM signing of emails through outMail?
Problem Solving
Below is a list of common gotchas.
SASL authentication failure
In your postfix logs you see message smilar to "mail postfix/smtp: warning: SASL authentication failure"
Double check you did the following
postmap /etc/postfix/relay_passwd postfix reload
Summary of server details
Outgoing server |
mxXXXXXX.smtp-engine.com As provided in your signup email. |
Outgoing server protocol |
SMTP |
Outgoing server port |
25, 465, 587, 2525 or 8025 |
Authentication Type |
Basic Authentication, SSL and TLS supported |
Username |
As provided |
Password |
As provided |