Set Up msmtp with Per-Account Profiles#
Prerequisites#
msmtpinstalled and at least one account working.If you are new to msmtp, complete Setting Up msmtp for Sending first.
Add Multiple Account Blocks#
Edit your msmtp config file (
~/.config/msmtp/configor~/.msmtprc):
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.config/msmtp/msmtp.log
account personal
host smtp.example.com
port 465
tls_starttls off
from you@example.com
user you@example.com
passwordeval "pass mail/you@example.com"
account work
host smtp.company.com
port 587
tls_starttls on
from work@company.com
user work@company.com
passwordeval "pass mail/work@company.com"
account default : personal
The account default : personal line sets a fallback account.
Expected result: msmtp -a personal and msmtp -a work each use the correct server.
Test Each Account#
Send a test message from each:
echo "Test personal" | msmtp -a personal you@example.com
echo "Test work" | msmtp -a work work@company.com
Check the log:
tail ~/.config/msmtp/msmtp.log
Expected result: both messages are delivered successfully.
Switch Accounts in NeoMutt with folder-hook#
Add folder-hooks that set
$sendmailwhen you enter each account’s mailbox:
folder-hook "you@example.com" "set sendmail='msmtp -a personal'"
folder-hook "work@company.com" "set sendmail='msmtp -a work'"
Expected result: composing a message from a work mailbox sends via the work SMTP account.
Switch Accounts with send-hook#
If you want to select the account based on the sender address rather than the current folder:
send-hook '~f you@example.com' "set sendmail='msmtp -a personal'"
send-hook '~f work@company.com' "set sendmail='msmtp -a work'"
Expected result: the SMTP account matches the From address on the outgoing message.
Set a Default Account in NeoMutt#
Set the default sendmail value before your hooks:
set sendmail = "msmtp -a personal"
Expected result: messages use the personal account unless a hook overrides it.
Enable Delivery Logging#
The logfile line in the msmtp config records every delivery attempt.
Check it when troubleshooting:
tail -20 ~/.config/msmtp/msmtp.log
Expected result: each entry shows the account used, the recipient, and the server response.
See Setting Up msmtp for Sending for the full setup tutorial and Hooks for more on NeoMutt hooks.