I'm attempting to set up multiple Gmail accounts using mu4e-context's. I have a lot of the features working except one. I can switch between contexts, update my mail in each account (using offlineimap) and I can send mail.

The problem is that I have multiple lines in my .authinfo file, that have the same hostname - I was assuming that mu4e would be able to differentiate by username, this appears to not be the case. It doesn't matter which context I am in, the mail is always being sent from the account that is configured first in the .authinfo file.

I don't know how to make each context use separate credentials for logging into the Gmail SMTP Server.

I thought about attempting to set up some hostname aliases so that personal.gmail.com and work.gmail.com both resolve to smtp.gmail.com so that I can give them separate machine names in authinfo, but I am unsure how to achieve this (on OSX) or even if it's a sensible way to solve this problem (Ideally I'd not have to monkey around with config outside of Emacs).

My authinfo looks like this

machine smtp.gmail.com login [email protected] port 587 password fakepassword
machine smtp.gmail.com login [email protected] port 587 password fakepassword

and the relevant parts of my mu4e-config is:

(setq mu4e-get-mail-command "offlineimap")
(setq mail-user-agent 'mu4e-user-agent)
(setq message-send-mail-function 'smtpmail-send-it)

(setq smtpmail-stream-type 'starttls)
(setq smtpmail-default-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 587)

(setq mu4e-contexts
      `( ,(make-mu4e-context
           :name "personal"
           :enter-func (lambda () (mu4e-message "Switch to Personal context"))
           ;; leave-func not defined
           :match-func (lambda (msg)
                         (when msg
                           (mu4e-message-contact-field-matches msg :to "[email protected]")))
           :vars '(  (user-mail-address . "[email protected]"  )
                     (mu4e-drafts-folder . "/personal/drafts")
                     (mu4e-sent-folder   . "/personal/sent")
                     (mu4e-trash-folder  . "/personal/bin")
                     (mu4e-maildir-shortcuts . (("/personal/INBOX" . ?i)
                                                ("/personal/sent"  . ?s)
                                                ("/personal/bin"   . ?t)))
                     (smtpmail-mail-address . "[email protected]")
                     (user-full-name    . "Matt Valentine-House" )))
           :name "work"
           :enter-func (lambda () (mu4e-message "Switch to Work context"))
           ;; leave-fun not defined
           :match-func (lambda (msg)
                         (when msg
                           (mu4e-message-contact-field-matches msg :to "[email protected]")))
           :vars '(  (user-mail-address . "[email protected]" )
                     (mu4e-drafts-folder . "/work/drafts")
                     (mu4e-sent-folder   . "/work/sent")
                     (mu4e-trash-folder  . "/work/bin")
                     (mu4e-maildir-shortcuts . (("/work/INBOX" . ?i)
                                                ("/work/sent"  . ?s)
                                                ("/work/bin"   . ?t)))
                     (smtpmail-mail-address . "[email protected]")
                     ( user-full-name    . "Matthew Valentine-House" )))))
  • Were you able to resolve this?
    – ppbitb
    Sep 21, 2017 at 16:35

1 Answer 1


It's been almost two years since the question was asked, but I have just had the same problem and I managed to solve it using the smtpmail-smtp-user variable. In the manual it says:

If the variable smtpmail-smtp-user is set to a non-nil value, then only entries for that user are considered.

In my personal context vars I have:

(smtpmail-smtp-user . "[email protected]")

In my work context vars I have:

(smtpmail-smtp-user . "[email protected]")

I've only tested it briefly, but it seems to work properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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