Configure different SMTP users per WP site


I’ve faced this limitation with Trellis that it’s not really possible to use different SMTP login/domain account per project - in case there are multiple projects managed by one Trellis installation.

What I mean is that mail.yml is placed in group_vars/all. I’ve got MailGun configured as my SMTP service provider. In MailGun, I set up multiple domains to use with my WP projects managed by Trellis.

However, it seems that I’m forced to use one MailGun SMTP login credentials for all my projects. As a consequencte, the emails I send from my sites would have headers like:

... ..... via

If I send mail from, the account will be again used internally by sSMTP, so the outgoing email header would again b

... ..... via

It’s not good at all. I should be able to use a different login account to have a sender’s header ... ..... via form project

Is there a way to assign unique SMTP login credentials on per-project basis with Trellis?


I’m not exactly sure but sSTMP only has a single config file. So it’s not like you can have multiple domains in its config.

But it does have a setting which should work for you:

# Email 'From header's can override the default domain?

Trellis already sets that to yes by default.

So if PHP/WordPress is properly setting the From header then it might work as you want it to.

1 Like

Thank’s for pointing this out.

I’ve actually found that my problem is a bit deeper and it’s a consequenct of Google’s police Google mail headers policy

Indeed, I can change the signature header of the outgoing mail with WP/PHP, but via.. part is added by Google as a consequence of me sending email from while being singed up to the SMTP service as user.

To make the email not take via ... part, I’d have to either host each project on a separate infrastructure (would be unnecessarily expensive) or find a way to make sSMTP use different SMTP login credentials per project (which might not be possible).

It seems that it’s not going to be so easy.

I’ve had success swapping ssmtp for msmtp, which can have multiple accounts. I made fairly trivial changes to this third-party role


This is perfect, thanks so much for sharing.

@DaveNaylor, I’m about to configure msmtp for my server. I was wondering - have you also installed Mutt in order to make it possible to send email through different accounts depending on the sender’s address?

Not on the server, but Mutt is my personal email client of choice and I do exactly that for local email.

I’m facing the same issue right now. Either I set up a new trellis instance or I extend the current one with an additional site.

@DaveNaylor can you tell a bit about your experience with the msmtp setup? Did everything work fine so far? Would you recommend doing it again? Do I understand it right, you then still use Mailhog but with msmtp instead of ssmtp?

Anyone else any recommendations how to handle the mail issue with multiple sites and one trellis instance? From reading through threads I guess a lot of people are using Trellis to have multiple sites running, so I guess there must be some more experience around this topic? :slight_smile:

What changes have you made to the role to make it support multiple accounts?
Are you also using password encryption to avoid storing the password in plain text (
After setting up msmtp each WordPress site can just mail out and msmtp will automatically pick the right account for sending the mail?