Sail Knowledgebase

Installing a Postfix SMTP Relay for WordPress with Sail

This guide will demonstrate how to use the postfix.yaml blueprint for Sail to install and configure a Postfix SMTP relay.

If you like Sail, consider sponsoring us via GitHub!

Why use an SMTP relay?

Using a third-party SMTP service will significantly improve the chance of your e-mail landing in the recipient's inbox. These services will handle (for a small fee) delivery, abuse, spam, bounces, retries and all the other e-mail related things, which most hosting providers will not want to deal with.

You can send e-mails through a third-party SMTP service in WordPress by using a free or paid plugin, however we do NOT recommend that for performance reasons.

Instead, we recommend using a local SMTP relay. This will prevent WordPress from performing external connections, and instead handle queueing of e-mail messages locally, then let the relay software deliver these messages to your SMTP service.

Sail makes this incredibly easy to set up.

Get your SMTP credentials

You'll need to have your SMTP credentials ready before continuing. If you're looking for a third-party SMTP service, here's a list of ones we tested with Sail:

Find your SMTP username, SMTP password, SMTP host and SMTP port (usually 587). You will use these in the next step.

Install and configure Postfix

To install and configure a Postfix SMTP relay with Sail, run:

sail blueprint postfix.yaml

The blueprint will prompt for your SMTP credentials, or you can provide them on the command line with:

  • --smtp-username - your SMTP username
  • --smtp-password - the SMTP password
  • --smtp-host - the hostname of the third-party SMTP service
  • --smtp-port - the SMTP port it's listening on, usually 587

There are two additional configuration variables, related to WordPress:

  • --from-name - the default name for the From header for outgoing mail in WordPress
  • --from-email - the default outgoing e-mail address for the same From header

After the blueprint is applied successfully, you can test delivery.

Send a test e-mail

A test e-mail can be sent with a WP-CLI shell:

$ sail wp shell
wp> wp_mail( 'your@email.address', 'Test from Sail', 'The body' );
=> bool(true)

If the message has not reached your inbox, try checking your spam folder, the Sail mail logs with sail logs --postfix, or the logs at your third-party SMTP provider.

For help with configuring e-mail with Sail, visit our getting help section.