Applicable to:
- Plesk for Linux
Question
How to configure Postfix to send emails using SendGrid in Plesk?
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: The configuration below is not compatible with the Plesk Email Security extension. Consider removing it before applying the changes below
-
Connect to the server via SSH.
-
Define which MTA is installed on the server and switch to Postfix if necessary.
-
Create a backup of the 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 -
Modify the following:
-
Add the SendGrid SMTP service as relayhost to the
/etc/postfix/main.cf
configuration file: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 Google 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 = noanonymous
smtp_sasl_tls_security_options = noanonymous
Additional step for Google Cloud instances-
Check if the following parameters exist and if so, comment them out by adding a 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
-
-
After the parameters are set, make sure that there are no duplicate directives that can break the configuration:
# cat /etc/postfix/main.cf | grep "relayhost|smtp_sasl_auth_enable|smtp_sasl_password_maps|smtp_sasl_security_options|smtp_sasl_tls_security_options|smtp_tls_security_level|header_size_limit"
Comment out/remove duplicate directives if there are some.
-
Generate the SASL password map using the API key from the SendGrid panel:
Note: Replace <your_SendGrid_API_Key_value> in the command below with the real API Key value:
# echo [smtp.sendgrid.net]:2525 apikey:<your_SendGrid_API_Key_value> >> /etc/postfix/sasl_passwd
-
Use the
postmap
utility to generate a.db
file:# postmap /etc/postfix/sasl_passwd
-
Verify that the
.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 proper permissions on the
.db
file:# chmod 600 /etc/postfix/sasl_passwd.db
-
Remove the file containing SendGrid API Key as it is no longer needed:
# rm /etc/postfix/sasl_passwd
-
Reload Postfix service to apply changes:
# service postfix restart
Comments
14 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.
It's bad enough that we have to resort to manually editing the Postfix config to enable an essential feature, but no stability is unacceptable.
I still don't understand why there is no option to configure this directly in the Plesk interface. Self-hosting outbound mail can be very problematic, and it's not surprising that most of us want to use external outbound mail services. I agree that having full control directly from Plesk is nice, but infrastructure simply does not allow it.
Also, please add extra clarification to this (https://support.plesk.com/hc/en-us/articles/115001743034-How-to-configure-an-external-SMTP-server-in-Plesk) support article. It took us a lot of back and forth to realize it's not it.
I am desperately in need to use this now. Any YouTube video for help?
Hello Chuks C,
Video instructions are not available for this article. Please follow the text instructions from the corresponding section based on whether your server is running on Google Cloud Instance or not.
Please sign in to leave a comment.