I'm using the latest stable emacs (26.1.91) compiled on my Debian 8 machine and I'm using ssmtp/sendmail to send emails. I'm trying to setup sending mail from multiple accounts within mu4e and it works for my work account (which is google) but not my personal account (also google).

I've got the passwords in the same file but have tried separate files and it also doesn't work. If I leave the 'smtpmail-smtp-user' command out then it seems to always default to my work account. I don't know why it does this but it seems like the problem.

Here is my mu4e configuration

;; Set up queue for offline email (use mu, mkdir  ~/Maildir/queue to set up first)
(setq smtpmail-queue-mail nil  ;; start in normal mode
      smtpmail-queue-dir   "~/Maildir/queue/cur")

;; Default sent & drafts
(setq mu4e-sent-folder   "/Work/[Gmail].Sent Mail")
(setq mu4e-drafts-folder "/Work/[Gmail].Drafts")

;; ;; Setup Async as the default sending function
;; (require 'smtpmail-async)

;; (setq
;;   send-mail-function 'async-smtpmail-send-it
;;   message-send-mail-function 'async-smtpmail-send-it)

;; Old way sending through smtpmail
  send-mail-function 'smtpmail-send-it
  message-send-mail-function 'smtpmail-send-it)

;; Setup Email account selection for sending email
(defvar my-mu4e-account-alist
     ;; Signature
     (user-full-name "Michael")
     ;; Folder settings
     (mu4e-sent-folder "/Work/[Gmail].Sent Mail")
     (mu4e-drafts-folder "/Work/[Gmail].Drafts")
     (user-mail-address "michael@work.com.au")
     ;; SMTP settings
     (smtpmail-smtp-user "michael@work.com.au")
     (smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))
     (smtpmail-auth-credentials (expand-file-name "~/.authinfo2.gpg"))
     (smtpmail-default-smtp-server "smtp.gmail.com")
     (smtpmail-smtp-server "smtp.gmail.com")
     (smtpmail-smtp-service 587)
     (smtpmail-debug-info t))
     ;; Signature
     (user-full-name "Michael")
     ;; Folder settings
     (mu4e-sent-folder "/Personal/[Gmail].Sent Mail")
     (mu4e-drafts-folder "/Personal/[Gmail].Drafts")
     (user-mail-address "<my email>@gmail.com")
     ;; SMTP settings
     (smtpmail-smtp-user "<my email>@gmail.com")
     (smtpmail-starttls-credentials '(("smtp.gmail.com" "587" nil nil)))
     (smtpmail-auth-credentials (expand-file-name "~/.authinfo2.gpg"))
     (smtpmail-default-smtp-server "smtp.gmail.com")
     (smtpmail-smtp-server "smtp.gmail.com")
     (smtpmail-smtp-service 587)
     (smtpmail-debug-info t)

;; Prompt user for 'from address' selection
(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((account
          (if mu4e-compose-parent-message
              (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                (string-match "/\\(.*?\\)/" maildir)
                (match-string 1 maildir))
            (completing-read (format "Compose with account: (%s) "
                                     (mapconcat #'(lambda (var) (car var))
                                                   my-mu4e-account-alist "/"))
                             (mapcar #'(lambda (var) (car var))
                             nil t nil nil (caar my-mu4e-account-alist))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
      (error "No email account found"))))

;; Prompt user just before composing an email
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)

If I try sending from the command line for both my work and personal email they both work.

echo "test" | /usr/sbin/ssmtp <my email>@gmail.com

Without the smtpmail-smtp-user "@gmail.com" in the personal settings then it sends but sets the from email to my work account and not my personal account like it should. If I include the smtpmail-smtp-user "@gmail.com" line then emacs will not send the email and tell me I've got the wrong username/password. This isn't the case as it works on the command line.

Here is my authinfo file maybe it's wrong;

machine imap.gmail.com login <work email> port 993 password <my pass>
machine smtp.gmail.com login <work email> port 587 password <my pass>
machine imap.gmail.com login <my email>@gmail.com port 993 password <my pass>
machine smtp.gmail.com login <my email>@gmail.com port 587 password <my pass>
  • 1
    You have two accounts for the same smtp server, that means you need two lines in .authinfo for that server. Note also that smtpmail-auth-credentials and smtpmail-starttls-credentials no longer exist. – rpluim Jan 19 '19 at 10:48
  • I've added the extra lines to .authinfo and it didn't make a difference. What do I use instead of smtpmail-auth-credentials and smtpmail-starttls-credentials? All the tutorials online include these in their config. – map7 Jan 20 '19 at 22:31
  • 1
    auth-sources is the variable used to tell auth-source where to look up usernames/passwords. The lookup uses smtpmail-smtp-server, smtpmail-smtp-service and smtpmail-smtp-user – rpluim Jan 21 '19 at 9:16
  • rpluim, Thanks that worked. I was using .authinfo2.gpg which wasn't in my auth-sources and wasn't aware that smtpmail-auth-credentials and smtpmail-starttls-credentials no longer exist. I removed those lines and added my password to .authinfo and it all started working! Thank you. – map7 Jan 21 '19 at 21:19

Your Answer

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

Browse other questions tagged or ask your own question.