[Best practices] Different mail settings per site


#1

I need different mail settings per WordPress site (multisite not enabled) on a Trellis server.
What is the current approach for defining mail settings for each site individually?


#2

Some more info here: Configure different SMTP users per WP site

But the feature doesn’t really exist in Trellis itself.


#3

What were the reasons for deciding to use a MTA like ssmtp or msmtp (as described in the link posted previously) instead to use a WordPress plugin (like https://wordpress.org/plugins/wp-mail-smtp/ or https://wordpress.org/plugins/easy-wp-smtp/)?


#4

A lot of the time it’s nice if the server can send mail on its own without relying on a plugin. With ssmtp, mail will work even when WordPress doesn’t, and it means that Trellis doesn’t require any plugins at all for basic functionality.

Which doesn’t mean you can’t use those plugins. They should work fine regardless of your ssmtp setup (correct me here, Roots team). There’s even a Mailgun plugin out there that’ll let you send via the Mailgun API rather than SMTP!


#5

Yeah in Trellis we can’t really require/depend on a WP plugin. That’s basically all there is to it.


#6

Then this boils down to two problems:

  1. The MTA in question (ssmtp) doesn’t support multiple accounts to send from.
  2. Even if a MTA is used that offers support for multiple accounts, WordPress core still has to communicate which account it should use, including proper auth, so not another account can be used from - which could be changed in the WordPress configuration.

When multiple sites are used, I think the only the way is using a WordPress plugin for directly configuring the WordPress SMTP settings.

Edit: A plugin is actually not low level enough. In a better, hybrid approach Trellis generates an .env file with the mail config - either localhost for the classic SSMTP setup - or with custom SMTP config - and some WordPress code applies these settings.
Programmatic way for configuring WordPress SMTP settings: https://wordpress.stackexchange.com/questions/75956/whats-the-easiest-way-to-setup-smtp-settings-programmatically