0

I would like mu4e to use smtpmail-send-it to send emails from emacs. I would like smtpmail-send-it to authenticate using pass. I have 2factor auth on my gmail account, so I have to use an App Password.

My emacs verison is: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16

Based on what I've read of the pass app built into emacs, I've set up my pass directory as such:

Password Store
    smtp.gmail.com
        (user)@gmail.com

(user)@gmail.com looks like this:

(app password, copied from my security profile in google)
host: smtp.gmail.com
user: (user)@gmail.com
port: 465

I'm using this directory structure because later I'd like to add my work account, which also uses gmail.

Based on instruction from the above mentioned pass library, from the emacs docs on auth-source, and from the mu4e manual, I've set up my config as follows (note spacemacs is involved, but I don't sense this is part of the issue) (this is not a raw copy/paste, I ripped out some stuff I thought unrelated, please ignore if there's mismatched parentheses or similar)

(setq smtpmail-stream-type 'tls)
(setq smtpmail-default-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 465)
(setq message-send-mail-function 'smtpmail-send-it )
(auth-source-pass-enable)
(setq auth-sources '(password-store))
(setq auth-source-debug t)
(setq auth-source-do-cache nil)

(with-eval-after-load 'mu4e
    (setq mail-user-agent 'mu4e-user-agent)
    (setq mu4e-user-mail-address-list '("((user)@gmail.com")
          )
    (setq mu4e-context-policy 'ask)
    (setq mu4e-contexts
          `( ,(make-mu4e-context
               :name "Personal"
               :match-func (lambda (msg)
                             (when msg
                               (string-match-p "^/gmailhome" (mu4e-message-field msg :maildir))))
               :vars '( ( user-mail-address     . "(user)@gmail.com"  )
                        (smtpmail-smtp-user . "(user)@gmail.com")
             ))
    )

The log shows the following:

Sending via mail...
auth-source-password-store: searching for ’(user)@gmail.com@smtp.gmail.com’ in entry names (user: (user)@gmail.com)
auth-source-password-store: no match found
auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: (user)@gmail.com)
Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done
auth-source-password-store: found 1 match: smtp.gmail.com/(user)@gmail.com
Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done
auth-source-password-store: return (:host smtp.gmail.com :port 465 :user (user)@gmail.com) as final result (plus hidden password)
auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "465" :user "(user)@gmail.com" :max 1 :require nil :create nil)
Decrypting /home/caleb/.password-store/smtp.gmail.com/(user)@gmail.com.gpg...done
smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials s69sm87755otb.4 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA==

At first I thought this error was because I mistakenly put my normal gmail password into pass, but now I've swapped it for a fresh app password, and I'm still getting this error.

I looked through a couple other questions on here with similar issues, but none seemed to have similar reasons for authentication failure.

How can I successfully authenticate and send mail?

EDIT: I read on google's support that I might have a mismatch with my (setq smtpmail-stream-type 'tls) and the port number, (setq smtpmail-smtp-service 465), so I changed to:

(setq smtpmail-smtp-service 587)

Now I'm getting the following error:

   Sending via mail...
    gnutls.el: (err=[-15] An unexpected TLS packet was received.) boot: (:priority NORMAL:%DUMBFW :hostname smtp.gmail.com :loglevel 0 :min-prime-bits 256 :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil)
gnutls-negotiate: GnuTLS error: #<process smtpmail>, -15

EDIT2: I changed to starttls

(setq smtpmail-stream-type 'starttls)

I also updated my pass entry to have `port: 587

And now am back to a user/password error.

Interestingly, the error appears to be identical to the same experiment as above, but when I forgot to change my pass entry's port. This makes me suspect that something's wrong with my pass config.

Error with wrong port in pass:

Sending via mail...
auth-source-password-store: searching for ’rogersjcaleb@gmail.com@smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com)
auth-source-password-store: no match found
auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com)
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
auth-source-password-store: found 1 match: smtp.gmail.com/rogersjcaleb@gmail.com
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
auth-source-password-store: return (:host smtp.gmail.com :port 465 :user rogersjcaleb@gmail.com) as final result (plus hidden password)
auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "587" :user "rogersjcaleb@gmail.com" :max 1 :require nil :create nil)
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials l24sm338725otf.59 - gsmtp
221 2.0.0 closing connection l24sm338725otf.59 - gsmtp
smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials l24sm338725otf.59 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA==

Error with right port in pass

Sending via mail...
auth-source-password-store: searching for ’rogersjcaleb@gmail.com@smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com)
auth-source-password-store: no match found
auth-source-password-store: searching for ’smtp.gmail.com’ in entry names (user: rogersjcaleb@gmail.com)
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
auth-source-password-store: found 1 match: smtp.gmail.com/rogersjcaleb@gmail.com
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
auth-source-password-store: return (:host smtp.gmail.com :port 587 :user rogersjcaleb@gmail.com) as final result (plus hidden password)
auth-source-search: found 1 results (max 1) matching (:host "smtp.gmail.com" :port "587" :user "rogersjcaleb@gmail.com" :max 1 :require nil :create nil)
Decrypting /home/caleb/.password-store/smtp.gmail.com/rogersjcaleb@gmail.com.gpg...done
535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials z13sm362612oth.10 - gsmtp
221 2.0.0 closing connection z13sm362612oth.10 - gsmtp
smtpmail-send-it: Sending failed: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials z13sm362612oth.10 - gsmtp in response to AUTH PLAIN AHJvZ2Vyc2pjYWxlYkBnbWFpbC5jb20AeGZiZ2xyemtpZWRlZ3ZobA==
0

This issue was solved when I manually edited my password in pass via pass edit smtp.gmail.com/(user)@gmail.com to be equivalent to my app password that's stored elsewhere inpass` for imap mail fetching.

I don't know why the newly created app password was invalid, and the old one is valid.

My config looks like the below now, and works:

Password Store
    smtp.gmail.com
      (user)@gmail.com

smtp.gmail.com/(username)@gmail.com/gpg

(old app password i was already using for IMAP)
host: smtp.gmail.com
user: (user)@gmail.com
port: 587

My emacs config:

(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 smtpmail-debug-info t)
(setq message-send-mail-function 'smtpmail-send-it )
(auth-source-pass-enable)
(setq auth-sources '(password-store))
(setq auth-source-debug t)
(setq auth-source-do-cache nil)
| improve this answer | |

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.