Subject: bug#78996: 29.4; Invalid authinfo credentials when sending mail through SMTP

From: 8dcc <[email-masked]>
Date: Fri, 11 Jul 2025 17:58:47 +0200

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 [email-masked] password "****" port 465
    machine smtp.gmail.com login [email-masked] password "****" port 465

Then the credentials of "[email-masked]" 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.