Skip to content

fix: handle non-x custom headers in MS Graph transport#6590

Open
gharlan wants to merge 1 commit into
5.xfrom
fix/msgraph-custom-headers
Open

fix: handle non-x custom headers in MS Graph transport#6590
gharlan wants to merge 1 commit into
5.xfrom
fix/msgraph-custom-headers

Conversation

@gharlan

@gharlan gharlan commented Jul 16, 2026

Copy link
Copy Markdown
Member

Fixes #6588

The Graph API only accepts custom headers whose name starts with x-/X- in internetMessageHeaders — any other header (e.g. Auto-Submitted, List-Unsubscribe as set by newsletter addons) makes the whole sendMail request fail with InvalidInternetMessageHeader, so no mail is sent at all.

This PR makes the MS Graph transport translate custom headers instead of passing them through blindly:

  • Headers with x- prefix (case-insensitive, checked on the header name) are passed to internetMessageHeaders as before.
  • List-Unsubscribe is mapped to the MAPI property PidTagListUnsubscribe (String 0x1045) via singleValueExtendedProperties, with the raw (non-MIME-encoded) value, since MAPI properties expect plain strings.
  • All other headers are dropped instead of failing the send.

Compared to the suggestion in the issue, this handles all non-x headers generically (e.g. Precedence, List-ID) instead of special-casing two of them, and checks the prefix on the header name rather than the value.

Auto-Submitted cannot be transmitted at all: Exchange strips it even from raw MIME submissions (msgraph-sdk-dotnet#2209, Microsoft Q&A). Callers who want to suppress auto-replies from Exchange recipients can set X-Auto-Response-Suppress: All instead. List-Unsubscribe-Post (RFC 8058 one-click) has no MAPI mapping either — full bulk-sender deliverability requirements can't be met via the Graph transport.

Testing note: I have no M365 tenant at hand — it would be great if someone with a Graph setup (e.g. the issue author) could verify that Exchange actually emits the List-Unsubscribe header on outbound mails sent this way.

The Graph API rejects the whole sendMail request if a custom header name
does not start with "x-". Only pass x-prefixed headers through to
internetMessageHeaders, map List-Unsubscribe to the MAPI property
PidTagListUnsubscribe (0x1045) via singleValueExtendedProperties, and drop
all other headers (e.g. Auto-Submitted, which Exchange strips even from
raw MIME) instead of failing the send.
@rex-bot rex-bot added the bug label Jul 16, 2026
@gharlan

gharlan commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

@davidspenner can you maybe test it?

@gharlan gharlan added this to the REDAXO 5.21.3 milestone Jul 16, 2026
@davidspenner

Copy link
Copy Markdown

@gharlan I just tested it and can confirm that it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

PHPMailer: Graph API does not support Auto-Submitted: auto-generated and List-Unsubscribe

3 participants