Multiple SMTP accounts using mSMTP and Mutt
Using sSMTP for a long time now, I had to say goodbye today. The reason is that I wanted to integrate multiple SMTP accounts, for example my GMail account, and sSMTP doesn’t support this.
I found mSMTP which looks very nice. It is lightweight like sSMTP and supports multiple accounts.
Below is my example configuration (stripped down to the basics) for msmtp and mutt.
This goes into msmtprc:
account default
host tachium.at
... tls fu ...
from cb@tachium.at
user cb@tachium.at
password XXX
account gmail
host smtp.gmail.com
from ch.blank@gmail.com
... tls fu ...
user ch.blank@gmail.com
password XXX
port 587
As you can see the first account is the default one (if I do not select a specific account when invoking mSMTP).
For the account selection, use something like this in your muttrc:
set sendmail="/usr/bin/msmtp"
set envelope_from=yes
macro generic "<esc>1" ":set from=cb@tachium.at"
macro generic "<esc>2" ":set from=ch.blank@gmail.com"
Now, if you send a mail mSMTP looks at the sender address and tries to find a corresponding ‘from’ entry in it’s configuration, or uses the default account if it cannot find one.
Note: You can select the account in different ways, eg. explicitly from the command line, the docs are a good starting point :)