Skip to main content

Multiple smtp accounts with mutt and msmtp [Resolved]

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:

defaults
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

Question Credit: lash
Question Reference
Asked September 17, 2019
Tags: mutt, msmtp
Posted Under: Unix Linux
19 views
2 Answers

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.


credit: krb
Answered September 17, 2019

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:

.muttrc

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"

.msmtprc

defaults
 ...

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

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

credit: wbob
Answered September 17, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA