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: example.com (👈 I typically use the TLD of my company, i.e. wenmarkdigital.com)
    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:

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 SendGrip account. Be sure to give it full access permissions.
  2. Create /etc/postfix/sasl_passwd and add the following:

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:
  1. Finally, restart Postfix:

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