I love me some SpinupWP (note: 👈 that’s my affiliate link 🙂). Their service lets you spin up a server on various cloud services, and it takes care of the backend (NGINX, PHP, Redis, MySQL, server updates, and automated backups). However, one thing they intentionally leave out is a mechanism for sending “transactional emails”. These are emails sent by your server on behalf of any applications you have running on it (i.e. WordPress admin emails or contact form notifications). I say “intentionally” here because there are multiple ways to solve this problem, and they leave that up to you.

My favorite way to enable transactional email sending on my SpinupWP servers is by installing Postfix and then integrating Postfix with my SendGrid account. Here’s how I do that:

Step 1: Install Postfix on your SpinupWP Server

By default, SpinupWP configures your server without Postfix installed. It’s what handles the actual sending of any emails sent by your server. Get it installed on your Ubuntu-based server by following these steps I’ve gleaned from this tutorial over at the Digital Ocean Community:

  1. SSH into your server using the sudo user you created when you spun it up with SpinupWP.
  2. Assume sudo privileges by entering sudo -i at the prompt (note: you’ll be asked for your sudo user’s password).
  3. Update your local apt package cache by entering:
    $ apt update
  4. Next you’ll issue the following command:
    $ DEBIAN_PRIORITY=low apt install postfix
  5. The installation process will present a series of prompts for which you’ll provide the following answers:

    General type of mail configuration? Internet Site
    System mail name: web1.example.com (👈 Use a domain representative of this server. Don’t use a TLD for anywhere you want to send email to: from this server, otherwise the server will route it to an internal mailbox and you won’t receive it.)
    Root and postmaster mail recipient: example (👈 Use your own TLD mail handle if you like)
    Other destinations to accept mail for: accept the defaults
    Force synchronous updates on mail queue? No
    Local networks: accept the defaults
    Mailbox size limit: setting this to 0 should be fine here
    Local address extension character: +
    Internet protocols to use: all

Step 2: Configure Postfix to send email with SendGrid

Once you have Postfix installed, now you’re going to configure it to send emails with SendGrid. The following is taken from this SendGrid tutorial:

  1. Edit /etc/postfix/main.cf and add the following to the bottom of the file:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

NOTE: You’ll want to comment out any previous settings the above lines are repeating. In most cases that means looking above these lines and commenting out pre-existing lines for smtp_tls_security_level and relayhost.

  1. Generate an API key in your SendGrid account. Be sure to give it full access permissions.
  2. Create /etc/postfix/sasl_passwd and add the following:
[smtp.sendgrid.net]:587 apikey:yourSendGridApiKey

Be sure to replace yourSendGridApiKey with the actual API key you generated in #2 above.

  1. Next we have to ensure the file you created has read/write access for root only, and then we run postmap to update Postfix’s hashtables to use this new file:
$ chmod 600 /etc/postfix/sasl_passwd
$ postmap /etc/postfix/sasl_passwd
  1. Finally, restart Postfix:
$ systemctl restart postfix

You can test that your server is sending emails through SendGrid by entering the following:

$ sendmail youremail@example.com
subject: Testing from Postix
This is my test email.
.

Need help with WordPress, Elementor, or anything else #web? Schedule a Zoom with me!