Problem/Motivation

Since updating to 2.3.0 from 2.2.2, the emails sent only have an attachment of type ".bin" and no body content. I ran all update scripts and exported the updated configuration. However, there is no body content.

Comments

shelane created an issue. See original summary.

larowlan’s picture

Category: Support request » Bug report

There's a patch here, can you review and report back? https://www.drupal.org/files/issues/2022-08-08/3219682-n1.patch

#3219682: Add support for HTML emails is related (the patch is from there)

Over there someone else reported the same issue as you

larowlan’s picture

https://git.drupalcode.org/project/workbench_email/-/merge_requests/12/d... is where we map html to text/html - can you debug that and see if your site isn't running that?

larowlan’s picture

Can you check the format key of your templates is set to HTML?

shelane’s picture

Yes, it was set to HTML. Without yet applying the patch, just switching to plain text restores functionality. It will be a while before I can push a patch out, especially having a working version of plain text.

larowlan’s picture

Hmm, that sounds like you have some other module interfering then
Do you have any other modules that implement hook_mail_alter or similar?

shelane’s picture

Category: Bug report » Support request

The email modules I have are swiftmailer and mailsystem.

mrshowerman’s picture

It looks like Swiftmailer is setting the wrong Content-type header, due to a parameter which is passed since Workbench Email 2.3.0.

In WorkbenchEmailProcessor, the format is passed to the $params array:

        $this->mailManager->mail('workbench_email', 'template::' . $template->id(), $data->getTo(), LanguageInterface::LANGCODE_DEFAULT, [
          'body' => $body,
          'template' => $template,
          'subject' => $subject,
          'format' => $format,
          'entity' => $entity,
        ], $replyTo);

It contains either text_plain or html, but Swiftmailer seems to expect a mime type instead. In \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::getContentType(), we have this:

    // The message parameter takes priority over config. Support the alternate
    // parameter 'format' for back-compatibility.
    $content_type = $message['params']['content_type'] ?? $message['params']['format'] ?? $this->config['message']['content_type'];
    // 1) check the message parameters.
    if ($content_type) {
      return $content_type;
    }

Here, the $message['params']['format'] contains the string html, which is taken for the Content-type header.

Not sure if this is a bug of SwiftMailer or the new functionality in Workbench Email, but we can work around this by additionally passing a real content type to $this->mailManager->mail(). Attaching a first patch.

mrshowerman’s picture

Status: Active » Needs review
mrshowerman’s picture

StatusFileSize
new1.64 KB

Reducing the change footprint in the patch so it can be applied together with #3017273: Recipient Type Email Field does not work for translated content, always uses original language value..

larowlan’s picture

Ah, so if the issue is that 'format' collides with a key used by Swiftmailer, how about we name it something else in $params?

E.g. template_format or similar?

larowlan’s picture

Title: Only getting email bin attachment » Only getting email bin attachment, collision with swiftmailer hook_mail params
Category: Support request » Bug report
mrshowerman’s picture

I'm not sure what the purpose of adding the format to the $params array in #3219682: Add support for HTML emails was, but in order not to break even more, I thought it was a better idea to add the content_type key additionally, which I knew would be caught by Swiftmailer in favor of format.

larowlan’s picture

StatusFileSize
new1.16 KB

This should do the trick, and is much smaller patch

shelane’s picture

If you change a config element, you might want to include an update hook.

larowlan’s picture

I'm not changing a config element. I'm just changing what we pass to hook_mail - another reason why this option is a lighter touch

mrshowerman’s picture

Nice!
I wasn't aware that the format parameter was only by coincidence named equally to what SwiftMailer expects, and that its only purpose was to be handled in hook_mail.

RTBC+1.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Nice, I'll wrap this up and release it tomorrow (evening here now)

  • larowlan committed b66da18 on 2.x
    Issue #3305863 by mrshowerman, larowlan, shelane: Only getting email bin...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Tagging 2.3.1 - thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.