Subject: Re: bug#68686: [Bug] smtpmail-send-queued-mail ignores some headers of the message it's sending!

From: Manuel Giraud <[email-masked]>
Date: Sat, 27 Jan 2024 12:25:56 +0100

[email-masked] writes:

> On 26.01.2024 16:37, Manuel Giraud wrote:
>> 
>>> Please do, because 29.2 is not packaged for guix, so I don't know how
>>> to install it. Otherwise I would test myself with 29.2...
>> Hi,
>> So I did the following test on 29.1 (built from source from the
>> emacs-29.1 branch):
>>       - emacs -Q
>>       - M-: (setq send-mail-function 'smtpmail-send-it
>>                   smtpmail-queue-mail t
>>                   smtpmail-smtp-server "ledu-giraud.fr")
>>       - M-: (compose-mail)
>>       [ manually change "To:" and "From:" to [email-masked] ]
>>       - C-c C-c
>>       - M-: (smtpmail-send-queued-mail)
>> And this mail is correctly delivered.  The only trace left of the
>> local
>> hostname is in "Message-ID:" which was set to
>> <[email-masked]>
>> So, I cannot see evidence of a bug in Emacs here.
>
> Ok I think I solved the conundrum! It has to do with the "envelope
> From", and I think the reason why you can't reproduce the error is
> because your smtp server allows envelope-from which are different from
> the From: header (and my smtp server doesn't). So you don't _see_ the
> bug. Let's keep start emacs -Q and let's set the parameters we
> discussed.
>
> For some reason, the envelope-from when sending via
> smtpmail-send-queued-mail is assigned to the value of
> user-mail-address (which for me was user@fedora) independently of the
> From: header. But with "immediate sending" this doesn't happen (I
> wonder if it's assigned to the same value as the header, or is not
> assigned at all and the smtp server assigns it? I don't know much
> about how these protocols work). In fact, if I just set a valid email
> for user-mail-address, then I get a different error, that is
> "envelope-from mismatches the From: header". Now, I could solve it by
> fiddling with
>
> '(mail-envelope-from 'header)
> '(mail-specify-envelope-from t)
>
> and at this point I can send queued email, but this is really a fishy
> business and this fact that the value assigned to envelope-from
> changes between using "immediate sending" and queued-sending I think
> is the real core of the bug.

Good.  It seems that you have tracked this issue down.  You're right
that the behaviour between "queued sending" and "immediate sending"
should not diverge here.  But on this matter it seems that there is a
lot of possible customization: for example, in message.el, there is also
'message-sendmail-envelope-from'.
-- 
Manuel Giraud