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

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

From
Aditya Garg via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 22, 2025, 07:19 UTC
Message-ID
<00e1be73ab91db1c37447544ebcdc4f33432dbcb.1745306351.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1949.git.git.1745306351.gitgitgadget@gmail.com>
From: Aditya Garg <gargaditya08@live.com>

Outlook does not accept the Message-ID header in the email body. Instead it saves it in its own proprietary X-Microsoft-Original-Message-ID header and a random Message-ID is set my the server. As a result, replying to threads does not work.

The $smtp->message variable in this script for outlook is something like this:

2.0.0 OK <Message-ID> [Hostname=Some-hostname]
This contains the Message-ID set by Microsoft in the first <>.

This patch retrieves the Message-ID from this server response and sets it in the email headers instead of using the self generated one.

Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 git-send-email.perl | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/git-send-email.perl b/git-send-email.perl
index aa6aad596f2..f2a926872de 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1799,6 +1799,17 @@ EOF
 			$smtp->datasend("$line") or die $smtp->message;
 		}
 		$smtp->dataend() or die $smtp->message;
+
+		# Retrieve the Message-ID from the server response in case of Outlook
+		if ($smtp_server eq 'smtp.office365.com' || $smtp_server eq 'smtp-mail.outlook.com') {
+			if ($smtp->message =~ /<([^>]+)>/) {
+				$message_id = "<$1>";
+				print __("Outlook: Retrieved Message-ID: $message_id\n");
+			} 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) {
-- 
gitgitgadget
Previous: Julian Swagemakers via GitGitGadget
Message 3 of 3 in “Ad support for Oauth2 and fix message-id bug in outlook”
  1. 0/2 Ad support for Oauth2 and fix message-id bug in outlookAditya Garg via GitGitGadget, Apr 22, 2025
  2. 1/2 send-email: implement SMTP bearer authenticationJulian Swagemakers via GitGitGadget, Apr 22, 2025
  3. 2/2 send-email: retrieve Message-ID from outlook SMTP serverAditya Garg via GitGitGadget, Apr 22, 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.