Postfix on Plesk server on Google Cloud using SendGrid

Want to configure Postfix on the Plesk server on Google Cloud? We can help you

It is quite common that we may receive incoming mail. However, the outgoing messages get stuck in the queue.

As part of our Google Cloud Platform Services, we assist our customers with several Google Cloud queries.

Today, let us see how we can add Postfix on the Plesk server on Google Cloud.

 

Send email from a Plesk server on Google Cloud

To configure sending emails, we need to use one of the following solutions:

  • Use one of Compute Engine’s third-party partners to set up and send emails through their servers.
  • Use a G Suite account to set up a relay service to send emails through it.

By default, Google Compute Engine blocks the SMTP ports, 25, 465, and 587. It does not allow outbound connections on them.

In such a case, Instances can receive emails. However, it does not allow sending emails from these ports.

 

Postfix on Plesk server on Google Cloud

Moving ahead, let us discuss how to configure Postfix on the Plesk server to send emails using SendGrid.

  1. Initially, we connect to the server via SSH.
  2. Then we define the MTA on the server and switch to Postfix if necessary.
  3. Later, we create a backup of the original /etc/postfix/main.cf configuration file and open it in a text editor:
    # cp -a /etc/postfix/main.cf{,.original}
    # vi /etc/postfix/main.cf
  4. Adjust it in accordance with the Google documentation instructions.

Then we check if the following parameters exist and comment them out by adding a hashtag sign to its beginning:

default_transport = error
relay_transport = error

Comment it out like this:

#default_transport = error
#relay_transport = error

We add the SendGrid SMTP service as relayhost:

relayhost = [smtp.sendgrid.net]:2525

Here, we use port 2525 because Compute Engine does not allow outbound connections on ports 25, 587.

Then we add the following lines at the end of the file:

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

Once we set the parameters, we ensure 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”

In case we find any, we comment out/remove them.

Then we generate the SASL password map:

# echo [smtp.sendgrid.net]:2525 yourSendGridUsername:yourSendGridPassword >> /etc/postfix/sasl_passwd

We use the postmap utility to generate a .db file:

# postmap /etc/postfix/sasl_passwd

We can verify the creation of the .db file using:

# ls -l /etc/postfix/sasl_passwd*
-rw——- 1 root root … /etc/postfix/sasl_passwd
-rw——- 1 root root … /etc/postfix/sasl_passwd.db

To set the proper permissions on .db file, we run:

# chmod 600 /etc/postfix/sasl_passwd.db

Then we remove the file containing SendGrid credentials:

# rm /etc/postfix/sasl_passwd

Finally, we reload the Postfix service to apply changes:

# service postfix restart

[Stuck with the process? We’d be happy to assist you]

 

Conclusion

In short, we saw how our Support Techs configure Postfix on the Plesk server on Google Cloud.

The post Postfix on Plesk server on Google Cloud using SendGrid appeared first on Bobcares.