LegacyEmailBuilder seems to have changed API?

Created on 14 January 2023, almost 2 years ago
Updated 21 November 2023, about 1 year ago

Problem/Motivation

I started getting this error message recently after updating and it seems like the API must have moved on us recently.

TypeError: Unsupported operand types: null + array in Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder->preRender() (line 88 of symfony_mailer/src/Plugin/EmailBuilder/LegacyEmailBuilder.php). 

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Fixed

Version

1.4

Component

Code

Created by

🇨🇦Canada joelpittet Vancouver

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada lambic

    What would that small change be?

  • 🇨🇦Canada joelpittet Vancouver

    Sorry for delayed response.

    We are going to stay away from symfony_mailer for now. I feel it diverges too much from core's mailer it will likely have issue integrating with other modules that use core's API (even when using the "legacy" mode). It very much may be the future and be a brilliant idea, and I do hope it is realized and I'll come back to it periodically to see how things mature.

  • Status changed to Active about 1 year ago
  • 🇨🇦Canada lambic

    I'm getting this error, but in the build phase not the pre-render phase:

    TypeError: Unsupported operand types: null + array in Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder->build() (line 107 of modules/contrib/symfony_mailer/src/Plugin/EmailBuilder/LegacyEmailBuilder.php)

    Here's the code we use to send the email:

          $to = new Address($to, $toname, $language->getId());
          $from = new Address($from, $fromname, $language->getId());
          $htmlMessage = $payload->getMessage();
          $converter = new Html2Text($htmlMessage, ['do_links' => 'table']);
          $textMessage = $converter->getText();
          $result = $this->mailer2->newTypedEmail($module, $key)
            ->setTo($to)
            ->setFrom($from)
            ->setReplyTo($reply)
            ->setBody([
              '#markup' => $htmlMessage,
            ])
            ->setTextBody($textMessage)
            ->setSubject($payload->getSubject())
            ->send();
    
  • 🇨🇦Canada lambic

    I got this working by changing the above code to:

           $mail = $this->mailer2->newTypedEmail($module, $key, [
              'id' => $module,
              'send' => TRUE,
              'module' => $module,
              'key' => $key,
              'subject' => $payload->getSubject(),
              'body' => [Markup::create($htmlMessage)],
            ]);
            $to = new Address($to, $toname, $language->getId());
            $from = new Address($from, '"'.$fromname.'"', $language->getId());
            $mail->setTo($to);
            $mail->setFrom($from);
            $mail->setReplyTo($reply);
            $mail->setTextBody($textMessage);
            $result = $mail->send();

    but I'm noticing that the from and to headers are in lowercase, I think they're supposed to be 'From' and 'To'?

  • 🇬🇧United Kingdom adamps

    LegacyEmailBuilder is part of the implementation to handle emails sent using the old API. MailManagerInterface is an API, but LegacyEmailBuilder isn't. If you have code to use MailManagerInterface that became broken then I agree it could be an API change.

    The code in #6 is using the new API. It's strange that LegacyEmailBuilder is called at all. Perhaps you also have a hook_mail implementation?? If so, that's the problem - you are mixing the old and new API.

    I'm noticing that the from and to headers are in lowercase, I think they're supposed to be 'From' and 'To'?

    I believe this comes from the Symfony\Component\Mime\Header\Headers class in symfony library (not this module).

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024