Project

General

Profile

Actions

Bug #100016

closed

"X-Mailer: TYPO3" will be set many times

Added by Ralph Brugger over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Mailer API
Start date:
2023-02-23
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

We're using a code like this:

/** @var MailMessage $email */
$this->email = GeneralUtility::makeInstance(MailMessage::class);

foreach ($recipientChunk as $recipient){

        $this->email
            ->to($recipient->getEmail())
            ->from($newsletter->getSender())
            ->replyTo($newsletter->getReplyTo())
            ->subject($newsletter->getSubject());
...
...
...
        $this->email
            ->html($htmlContent)
            ->text($textContent);
...
...
        $this->email->send();

}

We're trying to instantiate as less as possible, so the MailMessage-Object is reused.

The problem is that the core (Mailer.php) does this:

    public function send(RawMessage $message, Envelope $envelope = null): void
    {
        ...
        $message->getHeaders()->addTextHeader('X-Mailer', $this->mailerHeader);

With each mail in the loop there will be a new "'X-Mailer: TYPO3" added.
We're having a loop with hundreds of recipients, so the header will get to large:

Reporting-MTA: dns; mgmt.***.backend
Diagnostic-Code: smtp; 552 5.6.0 Headers too large (32768 max)

It would better to check if the header ist set before:

        $headers = $message->getHeaders();
        if (! $headers->has('X-Mailer')){
            $headers->addTextHeader('X-Mailer', $this->mailerHeader);
        }

or
        $headers = $message->getHeaders();
        if (! $headers->has('X-Mailer')){
            $header->remove('X-Mailer');
        }
        $headers->addTextHeader('X-Mailer', $this->mailerHeader);

Actions

Also available in: Atom PDF