Applicable to:
- Plesk for Linux
Question
How to configure Postfix to send emails using SendGrid?
Answer
Note: The steps below describe how to configure integration with 3rd-party service and should be performed on the server's administrator risk. Or consider this task to be handled by Plesk Professional Services
Warning: any customization made in Postfix configuration can be overwritten by Plesk update (for example, in case of bug fix, when configuration files are updated), Plesk upgrade or by mchk
utility, which resets default mail server configuration.
Google Cloud Instance
Click here to expand the solution.
- Connect to the server using SSH.
- Define which MTA is installed on the server and switch to Postfix if necessary.
- Create a backup of original
/etc/postfix/main.cf
configuration file and open it with a text editor:# cp -a /etc/postfix/main.cf{,.original}
# vi /etc/postfix/main.cf - Adjust it in accordance to the Google documentation instructions (Run Postfix on your instance section, starting from Step 3):
- check if there are the following parameters exist and comment them out by adding hashtag sign in the beginning of the line:
CONFIG_TEXT: default_transport = error
relay_transport = errorCommented out directives
CONFIG_TEXT: #default_transport = error
#relay_transport = error - add the SendGrid SMTP service as relayhost:
CONFIG_TEXT: relayhost = [smtp.sendgrid.net]:2525
Note: That port 2525 is used, because the outbound connections on ports 25, 587 are not allowed on Compute Engine.
- add the following lines at the end of the file:
CONFIG_TEXT: smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
header_size_limit = 4096000
smtp_sasl_security_options = noanonymousAfter the parameters set, make sure that there are no duplicate directives that can break the configuration:
# cat /etc/postfix/main.cf | grep "relayhost\|smtp_tls_security_level\|smtp_sasl_auth_enable\|smtp_sasl_password_maps\|header_size_limit\|smtp_sasl_security_options"
Comment out/remove duplicate directives if there are some.
-
generate the SASL password map:
# echo [smtp.sendgrid.net]:2525 yourSendGridUsername:yourSendGridPassword >> /etc/postfix/sasl_passwd
where:
yourSendGridUsername is your SendGrid username.
yourSendGridPassword is your SendGrid password. -
use the postmap utility to generate a .db file:
# postmap /etc/postfix/sasl_passwd
-
verify that .db file has been created:
# ls -l /etc/postfix/sasl_passwd*
-rw------- 1 root root ... /etc/postfix/sasl_passwd
-rw------- 1 root root ... /etc/postfix/sasl_passwd.db -
set the proper permissions on .db file:
# chmod 600 /etc/postfix/sasl_passwd.db
-
remove the file containing SendGrid credentials, as it is no longer needed:
# rm /etc/postfix/sasl_passwd
-
reload Postfix service to apply changes:
# service postfix restart
- check if there are the following parameters exist and comment them out by adding hashtag sign in the beginning of the line:
Configure SendGrid for regular server
Click here to expand the solution.
- Connect to the server using SSH.
- Define which MTA is installed on the server and switch to Postfix if necessary.
- Create a backup of original
/etc/postfix/main.cf
configuration file and open it with a text editor:# cp -a /etc/postfix/main.cf{,.original}
# vi /etc/postfix/main.cf - Adjust it in accordance to the SendGrid documentation instructions (Run Postfix on your instance section, starting from Step 3):
- add the SendGrid SMTP service as relayhost:
CONFIG_TEXT: relayhost = [smtp.sendgrid.net]:587
- add the following lines at the end of the file:
CONFIG_TEXT: smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
header_size_limit = 4096000
smtp_sasl_security_options = noanonymousAfter the parameters set, make sure that there are no duplicate directives that can break the configuration:
# cat /etc/postfix/main.cf | grep "relayhost\|smtp_tls_security_level\|smtp_sasl_auth_enable\|smtp_sasl_password_maps\|header_size_limit\|smtp_sasl_security_options"
Comment out/remove duplicate directives if there are some.
-
generate the SASL password map:
# echo [smtp.sendgrid.net]:587 yourSendGridUsername:yourSendGridPassword >> /etc/postfix/sasl_passwd
where:
yourSendGridUsername is your SendGrid username.
yourSendGridPassword is your SendGrid password. -
use the postmap utility to generate a .db file:
# postmap /etc/postfix/sasl_passwd
-
verify that .db file has been created:
# ls -l /etc/postfix/sasl_passwd*
-rw------- 1 root root ... /etc/postfix/sasl_passwd
-rw------- 1 root root ... /etc/postfix/sasl_passwd.db -
set the proper permissions on .db file:
# chmod 600 /etc/postfix/sasl_passwd.db
-
remove the file containing SendGrid credentials, as it is no longer needed:
# rm /etc/postfix/sasl_passwd
-
reload Postfix service to apply changes:
# service postfix restart
- add the SendGrid SMTP service as relayhost:
Comments
11 comments
I have configured according to the document but how can we test that configuration working properly?
server team try to send a test message for example with webmail, review then /var/log/maillog to see if message was sent by the server.
Please provide a solution to avoid configuration overwrite by a Plesk update / upgrade.
An option to change default outbound SMTP port / relay port from the Plesk panel will be much better.
Hi LiveDNS Ltd,
I see your inquiry is being addressed already in a support ticket. As for the default port suggestion, I recommend creating a feature request about this in our User Voice if you feel it is important https://plesk.uservoice.com/forums/184549-feature-suggestions. In case it will become popular it may be implemented in future Plesk versions.
I created a feature request:
https://plesk.uservoice.com/forums/184549-feature-suggestions/suggestions/41852380-custom-outgoing-smtp-port
Hopefully you will accept it so there won't be an outgoing mail issue on Google Cloud VMs.
hello,
it is possible to use amazon SES instead of sendgrid?
Hi, Artur Beqiraj!
Because we're not experts in Amazon SES, I'd recommend contacting Amazon Support/community to confirm if it can be used as an alternative.
It is obviously not a viable solution if it isn't persistent.
Is there no way to make this persistent? A non-persistent solution is no solution at all.
I saw https://support.plesk.com/hc/en-us/articles/115001743034-How-to-configure-an-external-SMTP-server-in-Plesk and thought that might be a solution, but that removes Dovecot.
Given how many hosts block outgoing mail, there should be a simple way to manage and receive domain email through Plesk while using an external SMTP server.
This is a critical feature. My VPS is on GoDaddy and they require outgoing mail to go through their relay server. I'm using ISP Config (which is an open source hosting manager) on another VPS server through GoDaddy and it has relay host setup built-in so I just assumed it was a normal feature. Without it neither I nor any of my clients can send emails unless I dig into the Postfix config and risk it getting broken on every update.
I agree with previous posters, there should be an easy and persistent solution to send emails via a third party SMTP provider whilst using Plesk to receive domain emails. It is a feature I need and I am struggling to piece together different apps to get something that works.
Please sign in to leave a comment.