git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 2/3] send-email: retrieve Message-ID from outlook SMTP server

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 23, 2025, 18:54 UTC
Message-ID
<xmqq5xiuzp1y.fsf@gitster.g>
In-Reply-To
<PN3PR01MB9597EFFF817F0FD3D8B3772DB8BA2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
Aditya Garg <gargaditya08@live.com> writes:
Show 8 quoted lines
> The script generates a Message-ID alongwith the other headers when
> gen_header is called, and is sent alongwith the email. For most email
> providers, including gmail, the Message-ID goes unchanged to the
> recipient.
>
> But, this does not seem to be a case with Outlook. In Outlook, when we
> send our own Message-ID as a part of the headers, it discards it. Rather
> it generates a new random Message-ID and that is was the recipient gets.

"Rather" -> "Then". "that is was the" -> "that is what the".

probably.
> The Message-ID we specified get stored as a part of Outlook's
> proprietary X-Microsoft-Original-Message-ID header.

For our purpose, X-MS-Original stuff is an extra noise that can be omitted, as there is no way we or recipients can make good use of the value on that field.

Show 25 quoted lines
> This is a problem because the Message-ID is crucial when we are sending
> multiple emails in a thread. The current implementation for threads in
> the script replies to the Message-ID it generated, but due to Outlook's
> behavior, it is not the same as the one that the recipient got, thus
> breaking threads. So a need arises to retrieve the Message-ID from the
> server response and set it in the In-Reply-To and References email
> headers instead of using the self generated one for the purpose of
> replies.
>
> The $smtp->message variable in this script for outlook is something like
> this:
>
> 2.0.0 OK <Message-ID> [Hostname=Some-hostname]
>
> The Message-ID here is the one the receipient gets, rather than the one
> the script generated.
>
> This patch uses the fact above and retrieves the Message-ID from the
> server response. It then changes the value of the $message_id variable
> to the one received from the server. This value will be used when next
> and subsequent messages are sent as replies to the message, thus
> preserving the threading of the messages.
>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
Thanks for a thorough description.  It reads very well.
Show 27 quoted lines
>  git-send-email.perl | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index a6cafda29c..a18e978e22 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1636,6 +1636,11 @@ sub gen_header {
>  	return ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header);
>  }
>  
> +sub is_outlook {
> +	my ($host) = @_;
> +	return ($host eq 'smtp.office365.com' || $host eq 'smtp-mail.outlook.com');
> +}
> +
>  # Prepares the email, then asks the user what to do.
>  #
>  # If the user chooses to send the email, it's sent and 1 is returned.
> @@ -1799,6 +1804,21 @@ sub send_message {
>  			$smtp->datasend("$line") or die $smtp->message;
>  		}
>  		$smtp->dataend() or die $smtp->message;
> +
> +		# Outlook discards the Message-ID header we set while sending the email.
> +		# It instead saves it in its proprietary X-Microsoft-Original-Message-ID
> +		# header and assigns a new random Message-ID to the email. So in order to
Again, "It instead ... header and" is probably better left unsaid.
> +		# avoid breaking threads, we simply retrieve the Message-ID from the server
> +		# response and assign it to $message_id.

Perhaps add ", which will then be assigned to $in_reply_to by the caller when the next message is sent as a response to this message" at the end?

Other than that, looks superb.  Thanks.
Show 12 quoted lines
> +		if (is_outlook($smtp_server)) {
> +			if ($smtp->message =~ /<([^>]+)>/) {
> +				$message_id = "<$1>";
> +				printf __("Outlook reassigned Message-ID to: %s\n"), $message_id;
> +			} else {
> +				warn __("Warning: Could not retrieve Message-ID from server response.\n");
> +			}
> +		}
> +
>  		$smtp->code =~ /250|200/ or die sprintf(__("Failed to send %s\n"), $subject).$smtp->message;
>  	}
>  	if ($quiet) {
Previous: Aditya GargNext: brian m. carlson
Message 8 of 63 in “send-email: add oauth2 support and fix outlook breaking threads”
  1. 0/3 send-email: add oauth2 support and fix outlook breaking threadsAditya Garg, Apr 23, 2025
  2. 1/3 send-email: implement SMTP bearer authenticationAditya Garg, Apr 23, 2025
  3. Junio C HamanoApr 23, 2025
  4. Aditya GargApr 23, 2025
  5. Greg Kroah-HartmanApr 24, 2025
  6. Aditya GargApr 24, 2025
  7. 2/3 send-email: retrieve Message-ID from outlook SMTP serverAditya Garg, Apr 23, 2025
  8. Junio C HamanoApr 23, 2025
  9. brian m. carlsonApr 23, 2025
  10. Aditya GargApr 24, 2025
  11. 3/3 send-email: add option to generate passswords like OAuth2 tokensAditya Garg, Apr 23, 2025
  12. Junio C HamanoApr 23, 2025
  13. Aditya GargApr 24, 2025
  14. Junio C HamanoApr 24, 2025
  15. M HickfordApr 23, 2025
  16. Aditya GargApr 24, 2025
  17. 0/3 send-email: add oauth2 support and fix outlook breaking threadsAditya Garg, Apr 24, 2025
  18. 1/3 send-email: implement SMTP bearer authenticationAditya Garg, Apr 24, 2025
  19. Julian SwagemakersApr 24, 2025
  20. 2/3 send-email: retrieve Message-ID from outlook SMTP serverAditya Garg, Apr 24, 2025
  21. Greg Kroah-HartmanApr 24, 2025
  22. Yao ZiApr 26, 2025
  23. Aditya GargApr 27, 2025
  24. Yao ZiApr 28, 2025
  25. Aditya GargApr 27, 2025
  26. 3/3 send-email: add option to generate passswords like OAuth2 tokensAditya Garg, Apr 24, 2025
  27. Julian SwagemakersApr 24, 2025
  28. Aditya GargApr 24, 2025
  29. Junio C HamanoApr 24, 2025
  30. Aditya GargApr 24, 2025
  31. Junio C HamanoApr 24, 2025
  32. 0/1 send-email: add oauth2 support and fix outlook breaking threadsAditya Garg, Apr 25, 2025
  33. 1/1 send-email: retrieve Message-ID from outlook SMTP serverAditya Garg, Apr 25, 2025
  34. Aditya GargApr 25, 2025
  35. Erik HuelsmannApr 25, 2025
  36. Junio C HamanoApr 25, 2025
  37. Erik HuelsmannApr 25, 2025
  38. Aditya GargApr 25, 2025
  39. Junio C HamanoApr 25, 2025
  40. Aditya GargApr 25, 2025
  41. Aditya GargApr 26, 2025
  42. Eric SunshineApr 26, 2025
  43. Aditya GargApr 26, 2025
  44. Junio C HamanoApr 28, 2025
  45. send-email: add --smtp-outlook-id-tweak optionAditya Garg, Apr 28, 2025
  46. send-email: add --smtp-outlook-id-tweak optionAditya Garg, Apr 28, 2025
  47. Junio C HamanoApr 28, 2025
  48. Aditya GargApr 29, 2025
  49. send-email: add --[no-]outlook-id-fix optionAditya Garg, Apr 29, 2025
  50. Aditya GargApr 29, 2025
  51. Junio C HamanoApr 29, 2025
  52. Junio C HamanoApr 29, 2025
  53. Aditya GargApr 29, 2025
  54. send-email: add --[no-]outlook-id-fix optionAditya Garg, Apr 29, 2025
  55. Junio C HamanoApr 29, 2025
  56. Aditya GargApr 30, 2025
  57. Aditya GargApr 24, 2025
  58. Erik HuelsmannApr 24, 2025
  59. Julian SwagemakersApr 25, 2025
  60. Aditya GargApr 25, 2025
  61. Aditya GargApr 25, 2025
  62. Erik HulsmannApr 25, 2025
  63. Aditya GargApr 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.