diff --git a/redaxo/src/addons/phpmailer/lib/mailer.php b/redaxo/src/addons/phpmailer/lib/mailer.php index 42114b3d47..cf22c12b3c 100644 --- a/redaxo/src/addons/phpmailer/lib/mailer.php +++ b/redaxo/src/addons/phpmailer/lib/mailer.php @@ -382,12 +382,31 @@ protected function microsoft365Send(): bool } $customHeaders = []; + $extendedProperties = []; /** @var array{string, string} $header */ foreach ($this->getCustomHeaders() as $header) { - $customHeaders[] = [ - 'name' => $header[0], - 'value' => $this->encodeHeader(trim($header[1])), - ]; + $name = trim($header[0]); + $value = trim($header[1]); + + if (str_starts_with(strtolower($name), 'x-')) { + $customHeaders[] = [ + 'name' => $name, + 'value' => $this->encodeHeader($value), + ]; + continue; + } + + if ('list-unsubscribe' === strtolower($name)) { + // MAPI property PidTagListUnsubscribe; Exchange emits it as List-Unsubscribe header + $extendedProperties[] = [ + 'id' => 'String 0x1045', + 'value' => $value, + ]; + continue; + } + + // The Graph API rejects the whole request for custom headers without "x-" prefix, + // so headers without a MAPI mapping (e.g. Auto-Submitted) have to be dropped } // Attachments für Graph API aufbereiten @@ -470,6 +489,9 @@ protected function microsoft365Send(): bool if (!empty($customHeaders)) { $mailData['message']['internetMessageHeaders'] = $customHeaders; } + if (!empty($extendedProperties)) { + $mailData['message']['singleValueExtendedProperties'] = $extendedProperties; + } if ('' !== $this->ConfirmReadingTo) { // MS Graph API unterstützt keine Read-Receipts an beliebige Empfänger $mailData['message']['isReadReceiptRequested'] = true;