Plesk

How to configure Postfix on a Plesk server to send emails using SendGrid

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

  1. Connect to the server via SSH.

  2. Define which MTA is installed on the server and switch to Postfix if necessary.

  3. 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

  4. Modify the following:

    • Add the SendGrid SMTP service as relayhost to the /etc/postfix/main.cf configuration file:

      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:

      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:

    default_transport = error
    relay_transport = error

    Commented out directives

    #default_transport = error
    #relay_transport = error