Wrong return value for MailManagerReplacement::mail()

Created on 8 November 2023, 8 months ago
Updated 21 November 2023, 7 months ago

Problem/Motivation

It seems MailManagerReplacement::mail() doesn't return the array for the formatted message. According to the docs MailManager::mail() return "the $message array structure containing all details of the message." It isn't 100% clear that this is the formatted / "as sent" message, but if you look at MailManager::doMail() it's clear that it formats the message body.

The use case is Views Send that spools the formatted message (to a SQL database) and sends it later with cron. I wonder if also Queue Mail might be affected.

Steps to reproduce

Sent a message. Checked the return array and observe that the body element contains plain HTML, not the MIME encoded message body. The is caused by LegacyMailerHelper::emailToArray() calling $email->getHtmlBody();.

There might be similar problems with other elements in the array.

Proposed resolution

Make sure that MailManagerReplacement follows MailManagerInterface closer.

Remaining tasks

πŸ› Bug report
Status

Active

Version

1.4

Component

Code

Created by

πŸ‡³πŸ‡΄Norway hansfn

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

Comments & Activities

  • Issue created by @hansfn
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Thanks for the report. If you can find an easy fix then I would accept it.

    MailManagerReplacement is not necessarily going to copy the exact implementation details of MailManager. Symfony provides its own spooling capability, so sites using this module are probably better using that.

  • πŸ‡³πŸ‡΄Norway hansfn

    I don't think the return value is an implementation detail ;-)

    The Views Send module tries to support multiple MIME enabling modules, and it has been a struggle since they tend to not follow MailManagerInterface closely. Since this module has this legacy support, I hoped to not write custom code.

    I'll see if there is an easy fix.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    > I don't think the return value is an implementation detail ;-)
    Yes but you already said yourself "It isn't 100% clear that this is the formatted / "as sent" message". You made your point by looking at the implementation of MailManager::doMail().

  • πŸ‡³πŸ‡΄Norway hansfn

    I was trying to be open about the fact that the documentation isn't sufficiently clear - and tried to support my claim with the core implementation of the interface. All other modules have I testet (at some point) - mailgun, mailchimp_transactional, mimemail, phpmailer_smtp, sendgrid_integration (and some older D7 modules) interpreted it to be the formatted message too.

    I have tried earlier to get the docs clearer, but failed to get any interest. Or, people are busy :-)

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Well I already said I'm willing to fix it if it's easyπŸ˜ƒ. It's possible that Symfony Mailer library doesn't actually make the information you would like available - this is basically what I'm trying to get at by saying "implementation detail".

    The other modules you are referring to are all @Mail plug-ins, so naturally they will provide this information, they implement a completely different interface.

    What I'm saying is that in my view the whole mail manager replacement concept is best-effort to aid transition to the new API. There is another module Drupal Symfony Mailer Lite for people who want exact BC. However eventually the old API is likely to removed from Core.

    The amount of my energy and free time that I wish to allocate this issue is limited, and at the moment you are using a lot of it up arguing with meπŸ˜ƒ.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    I'd like to add a more positive comment.

    support multiple MIME enabling modules, and it has been a struggle since they tend to not follow MailManagerInterface closely

    IMHO it's important to see that MailManagerInterface does not officially support MIME - it's an ancient API from the days of plain text mails over sendmail. Also it doesn't provide a clear definition of the distinction between compose and send. Sweiftmailer seems to split code fairly arbitrarily between the format and send functions.

    AFAICS this and πŸ› MailManagerReplacement::mail() doesn't always compose Active are related to a similar aim: using the $send flag to implement spooling over MailManagerReplacement. The $send flag was awkward to handle in this case as it didn't fit well with the symfony library. Perhaps it's never going to be perfect, and it's also perhaps not a widely needed case, because...

    Symfony Mailer library already supports spooling. So anyone who wants to use spooling with DSM should do that. There seems little point in putting effort into anything else. This means that Queue Mail is perhaps no longer needed with DSM. And Views Send could entirely skip everything related to spooling if DSM is also installed.

  • Status changed to Closed: won't fix 8 months ago
  • πŸ‡³πŸ‡΄Norway hansfn

    Thx for you time and effort. It seems the way forward is to avoid using MailManager (for Symfony Mailer) and rather implement support for Symfony Mailer using the new API. I also have little time to waste, you know.

    IMHO it's better to remove MailManagerReplacement as I think it gives false promises. You are of course technically correct - I was mixing to interfaces.

  • Status changed to Active 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    I'm sorry I wish I'd been more positive. It's quite challenging maintaining this module with so many people having different requests, and sometimes I get stressed.

    MailManagerReplacement is not perfect and I never intended or expected it to be perfect, but still it's being used successfully on 1000s of sites. In fact it's an extremely important part of this module, and no way can we remove it.

    I found a challenge in the dialogue here that seemed to be insisting and expecting a level of perfection that in fact I never promised. As I said before, I'm willing to fix it if it's easy. If not then we have other options.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS
Production build 0.69.0 2024