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:
- SSH into your server using the sudo user you created when you spun it up with SpinupWP.
- Assume
sudo
privileges by enteringsudo -i
at the prompt (note: youâll be asked for your sudo userâs password). - Update your local
apt
package cache by entering:$ apt update
- Next youâll issue the following command:
$ DEBIAN_PRIORITY=low apt install postfix
- 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 to0
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:
- Edit
/etc/postfix/main.cf
and add the following to the bottom of the file:
1 2 3 4 5 6 7 |
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
.
- Generate an API key in your SendGrip account. Be sure to give it full access permissions.
- Create
/etc/postfix/sasl_passwd
and add the following:
1 |
[smtp.sendgrid.net]:587 apikey:yourSendGridApiKey |
Be sure to replace yourSendGridApiKey
with the actual API key you generated in #2 above.
- Next we have to ensure the file you created has read/write access for
root
only, and then we runpostmap
to update Postfixâs hashtables to use this new file:
1 2 |
$ chmod 600 /etc/postfix/sasl_passwd $ postmap /etc/postfix/sasl_passwd |
- Finally, restart Postfix:
1 |
$ systemctl restart postfix |
You can test that your server is sending emails through SendGrid by entering the following:
1 2 3 4 |
$ sendmail youremail@example.com subject: Testing from Postix This is my test email. . |