GNU bug report logs -
#78996
29.4; Invalid authinfo credentials when sending mail through SMTP
Previous Next
Reported by: 8dcc <8dcc.lists <at> gmail.com>
Date: Sat, 12 Jul 2025 02:27:02 UTC
Severity: normal
Found in version 29.4
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 78996 in the body.
You can then email your comments to 78996 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sat, 12 Jul 2025 02:27:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
8dcc <8dcc.lists <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 12 Jul 2025 02:27:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello,
I have been trying to write a simple Emacs Lisp function that lets me
select the credentials that are used when sending mail through
`compose-mail' with `message-send-mail-function' set to
`smtpmail-send-it'. I tried many things, including modifying the "From:"
field, and changing `user-mail-address' (both locally and
globally). Although the "From" header does indeed change to the right
value when sending the email, the credentials used when authenticating
with the SMTP server don't change; in the case of Gmail, this "From"
header gets overwritten and a new "X-Google-Original-From" header is
added.
I thought that the email that was used for authentication was the one I
had originally set as `user-mail-address', but it turns out that it
entirely depends on the order of the entries in my '~/authinfo.gpg'
file.
For example, if the contents of the file were:
machine 127.0.0.1 login my-user port ssh password "****"
machine smtp.gmail.com login foo <at> gmail.com password "****" port 465
machine smtp.gmail.com login bar <at> gmail.com password "****" port 465
Then the credentials of "foo <at> gmail.com" would be used, since it's the
first line whose "machine" value matches the value of my
`smtpmail-smtp-server' variable.
Please let me know if you need any more information.
Thank you,
8dcc.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sat, 19 Jul 2025 08:09:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> From: 8dcc <8dcc.lists <at> gmail.com>
> Date: Fri, 11 Jul 2025 17:58:47 +0200
>
> I have been trying to write a simple Emacs Lisp function that lets me
> select the credentials that are used when sending mail through
> `compose-mail' with `message-send-mail-function' set to
> `smtpmail-send-it'. I tried many things, including modifying the "From:"
> field, and changing `user-mail-address' (both locally and
> globally). Although the "From" header does indeed change to the right
> value when sending the email, the credentials used when authenticating
> with the SMTP server don't change; in the case of Gmail, this "From"
> header gets overwritten and a new "X-Google-Original-From" header is
> added.
>
> I thought that the email that was used for authentication was the one I
> had originally set as `user-mail-address', but it turns out that it
> entirely depends on the order of the entries in my '~/authinfo.gpg'
> file.
>
> For example, if the contents of the file were:
>
> machine 127.0.0.1 login my-user port ssh password "****"
> machine smtp.gmail.com login foo <at> gmail.com password "****" port 465
> machine smtp.gmail.com login bar <at> gmail.com password "****" port 465
>
> Then the credentials of "foo <at> gmail.com" would be used, since it's the
> first line whose "machine" value matches the value of my
> `smtpmail-smtp-server' variable.
>
> Please let me know if you need any more information.
My reading of smtpmail.el is that you should set the value of
smtpmail-smtp-user to control the selection of credentials by login
name. Did you try that?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sat, 19 Jul 2025 14:26:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> My reading of smtpmail.el is that you should set the value of
> smtpmail-smtp-user to control the selection of credentials by login
> name. Did you try that?
I have just tried that, and it only seems to work if I set it
globally. Specifically, I added the following hook:
(add-hook
'message-send-hook
(lambda ()
(let ((from (mail-fetch-field "from")))
(when from
(let* ((components (mail-extract-address-components from))
(name (car components))
(addr (cadr components)))
(when name
(setq-local user-full-name name))
(when addr
(setq-local user-mail-address addr
smtpmail-smtp-user addr)))))))
If I modify the "From" address in the `message-mode' buffer, it does in
fact locally change `smtpmail-smtp-user' to the correct value
(bar <at> gmail.com). I have an entry in my '~/.authinfo.gpg' with that
address after the "login" keyword, but it still authenticates with the
first entry.
If I manually evaluate:
(setq smtpmail-smtp-user "bar <at> gmail.com")
It does work fine. Is this by design? Why doesn't it work if I use
`setq-local'?
Thank you.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sat, 19 Jul 2025 15:06:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> From: 8dcc <8dcc.lists <at> gmail.com>
> Cc: 78996 <at> debbugs.gnu.org
> Date: Sat, 19 Jul 2025 16:25:09 +0200
>
> > My reading of smtpmail.el is that you should set the value of
> > smtpmail-smtp-user to control the selection of credentials by login
> > name. Did you try that?
>
> I have just tried that, and it only seems to work if I set it
> globally. Specifically, I added the following hook:
>
> (add-hook
> 'message-send-hook
> (lambda ()
> (let ((from (mail-fetch-field "from")))
> (when from
> (let* ((components (mail-extract-address-components from))
> (name (car components))
> (addr (cadr components)))
> (when name
> (setq-local user-full-name name))
> (when addr
> (setq-local user-mail-address addr
> smtpmail-smtp-user addr)))))))
>
> If I modify the "From" address in the `message-mode' buffer, it does in
> fact locally change `smtpmail-smtp-user' to the correct value
> (bar <at> gmail.com). I have an entry in my '~/.authinfo.gpg' with that
> address after the "login" keyword, but it still authenticates with the
> first entry.
>
> If I manually evaluate:
>
> (setq smtpmail-smtp-user "bar <at> gmail.com")
>
> It does work fine. Is this by design? Why doesn't it work if I use
> `setq-local'?
Probably because smtpmail uses a different buffer for accessing the
authinfo? (That's a guess.)
But I don't understand why you cannot set the value globally. It
isn't like you need to send mail using several different credentials
at the same time, is it?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sun, 20 Jul 2025 04:36:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> From: 8dcc <8dcc.git <at> gmail.com>
> Cc: 8dcc.lists <at> gmail.com, 78996 <at> debbugs.gnu.org
> Date: Sun, 20 Jul 2025 00:07:09 +0200
>
> > But I don't understand why you cannot set the value globally. It
> > isn't like you need to send mail using several different credentials
> > at the same time, is it?
>
> I understand what you mean, but permanently modifying a global variable
> because I want to send a specific mail from a specific buffer doesn't
> seem right to me. For example, some other mode that uses SMTP could ends
> up accessing that same value, and since it's not hooked, it could end up
> using the email address from that one mail that I sent an hour ago,
> which is not my main one (i.e. what used to be the global value of
> `smtpmail-smtp-user').
>
> I could perhaps save the old value in my own variable, and then restore
> it in another hook, but that's very hacky and doesn't feel right at all.
You have message-send-hook and message-sent-hook to do this.
I don't understand why this is hacky, since your original code was
also in a hook.
Anyway, I think this bug can be closed now?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sun, 20 Jul 2025 10:51:04 GMT)
Full text and
rfc822 format available.
Message #20 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> Probably because smtpmail uses a different buffer for accessing the
> authinfo? (That's a guess.)
It seems that `smtpmail-send-queued-mail' uses `with-temp-buffer' before
reading `smtpmail-smtp-user'. Not sure if this is necessary, and if it
could be improved.
> But I don't understand why you cannot set the value globally. It
> isn't like you need to send mail using several different credentials
> at the same time, is it?
I understand what you mean, but permanently modifying a global variable
because I want to send a specific mail from a specific buffer doesn't
seem right to me. For example, some other mode that uses SMTP could ends
up accessing that same value, and since it's not hooked, it could end up
using the email address from that one mail that I sent an hour ago,
which is not my main one (i.e. what used to be the global value of
`smtpmail-smtp-user').
I could perhaps save the old value in my own variable, and then restore
it in another hook, but that's very hacky and doesn't feel right at all.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78996
; Package
emacs
.
(Sun, 20 Jul 2025 10:51:05 GMT)
Full text and
rfc822 format available.
Message #23 received at 78996 <at> debbugs.gnu.org (full text, mbox):
> You have message-send-hook and message-sent-hook to do this.
>
> I don't understand why this is hacky, since your original code was
> also in a hook.
I think modifying a global variable permanently from within a hook is
hacky, and I think saving it in a temporary variable across hooks is
also a hacky work-around. That's just my opinion.
> Anyway, I think this bug can be closed now?
Yes. Thank you for your help!
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sun, 20 Jul 2025 11:50:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
8dcc <8dcc.lists <at> gmail.com>
:
bug acknowledged by developer.
(Sun, 20 Jul 2025 11:50:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 78996-done <at> debbugs.gnu.org (full text, mbox):
> From: 8dcc <8dcc.git <at> gmail.com>
> Cc: 78996 <at> debbugs.gnu.org
> Date: Sun, 20 Jul 2025 12:21:40 +0200
>
> > You have message-send-hook and message-sent-hook to do this.
> >
> > I don't understand why this is hacky, since your original code was
> > also in a hook.
>
> I think modifying a global variable permanently from within a hook is
> hacky, and I think saving it in a temporary variable across hooks is
> also a hacky work-around. That's just my opinion.
Understood.
> > Anyway, I think this bug can be closed now?
>
> Yes. Thank you for your help!
Thanks, done.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 18 Aug 2025 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 32 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.