I use mutt with two different imap accounts, and have configured smtp accounts A and B with msmtp and mutt.

If I don't specify a default account in .msmtprc, mutt complains there is no default account when I try to send.

If I set a default account A, mutt uses this for all imap accounts.

How can I make it use the smtp account B for the corresponding imap account?

In the account B mutt config file I've set the following:

## sent
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="My Name"
set from=my@gmail.com
set hostname="gmail.com"
set ssl_force_tls=yes
set imap_pass=$my_pass
unset ssl_starttls

in .msmtprc the account configuration reads:

tls on
port 587


account gmail
tls_fingerprint 39:7C:59:20:DE:55:51:F4:8B:72:1D:B5:B2:26:8A:D1:DB:90:C6:28:80:77:F9:B5:EC:C1:BF:1C:6F:4D:A1:63
from my@gmail.com
host smtp.gmail.com
auth on
user my@gmail.com
passwordeval gpg2 --no-tty -q -d ~/mygmail.gpg

Inside your mutt configuration for the account (either A or B), you use:

set sendmail="/usr/local/bin/msmtp -a [account]

which tells msmtp which account parameters to use in .msmtprc. In my msmtp config, I specifically set the default to be na which forces the account to be set in mutt.

  • Two things: 1) I think this may need another " and 2) Why does this not work for me at all? It just gives me the error -a: unknown variable ???
    – gskapka
    Jun 8 '19 at 18:52
  • @gskapka - if you end the line with closing the quotation as you properly suspect, you shouldn't get the message "unknown variable". I too had a quotation problem, but it was after a send-hook. send-hook '~f "@gmail."' 'set sendmail="/usr/bin/msmtp -a gmail"'
    – wbob
    Jul 18 '20 at 10:36

there's section "Using msmtp with Mutt" within the EXAMPLES to the end of man msmtp.

The envelope_from=yes option lets Mutt use the -f option of msmtp. Therefore msmtp chooses the first account that matches the from address you@example.com.

This means in practice: do not specify an account in mutts set sendmail path to msmtp. But use some keyboard macro to switch between identities (and from) before sending. For the keyboard marco there are different ways - one of is mentioned in the manual. I'll give you another one and you can choose:


set sendmail="/usr/bin/msmtp"
set use_from=yes
set envelope_from=yes

alias gmail    Horton Bumblebee <hobumbl@gmail.com>
alias example  H. Bumblebee <hbum@example.com>
macro compose v "<edit-from>^Uidentity\_<tab>" "Select from"



account gmail
  host imap.gmail.com
  from hobumbl@gmail.com

account example
  host mail.example.com
  from hbum@example.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.