Support symfony_mailer, which doesn't use hook_mail_alter

Created on 1 February 2022, almost 3 years ago
Updated 10 October 2023, over 1 year ago

Problem/Motivation

symfony_mailer, the successor to swiftmailer, doesn't use hook_mail_alter, which reroute_email is based on.

symfony_mailer has a task to support reroute_email, ✨ Support for Reroute Email Closed: won't fix , but the current fix depends on to-be-deprecated backwards compatibility. It may be easier for reroute_email to support symfony_mailer, and it probably should anyway since it could replace the core mail system:

🌱 [META] Adopt the symfony mailer component Needs review
πŸ“Œ Add symfony/mailer into core RTBC

Steps to reproduce

Install and configure symfony_mailer and reroute_email
reroute_email doesn't do it's thing to symfony_mailer emails

Proposed resolution

A symfony_mailer maintainer provided this example we could build upon:

https://www.drupal.org/docs/contributed-modules/symfony-mailer-0/faq-tip... β†’

Alternatively we might be able to use some of the mailer hooks:

https://git.drupalcode.org/project/symfony_mailer/-/blob/1.x/symfony_mai...

It can probably use both hook_mail_alter and whatever method we'd use to override symfony_mailer. It doesn't look like any mail system would run both so no chance of double-processing.

✨ Feature request
Status

Fixed

Version

2.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States charginghawk

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.

  • πŸ‡ͺπŸ‡ΈSpain manuga

    The patch #15 is not working for me, commented in:
    https://www.drupal.org/project/reroute_email/issues/3340298#comment-1493... πŸ› Not working for contact form and Symfony Mailer Fixed

  • πŸ‡΅πŸ‡±Poland relim

    Changes done:

    • Rerolled #15 patch to work with reroute_email 2.2.0
    • Fixed attaching reroute information for symfony_mailer non-legacy emails
  • πŸ‡ΊπŸ‡ΈUnited States charginghawk

    It's somewhat alarming patch #15 would stop working if you updated, and then you'd start sending mails unexpectedly. That's for sure critical for symfony mailer users, and symfony mailer has a respectable 6500+ installs at this point, so marking critical.

  • πŸ‡§πŸ‡ͺBelgium mallezie Loenhout

    Just nothing that this approach does not work for mails sent by other mail builders then the LegacyEmailBuilder.

    That's the only plugin setting the needed parameter for reroute_email_mailer_build()

    /**
     * Implements hook_mailer_build().
     */
    function reroute_email_mailer_build(EmailInterface $email) {
      // Prevent calling reroute for symfony legacy email builder.
      // For the mode an email reroute is handled by symfony_mailer itself by invoke 'mail' hook.
      // @see \Drupal\symfony_mailer\Plugin\EmailBuilde\LegacyEmailBuilderr::createParams()
      if (!empty($email->getParam('legacy_message'))) {
        return;
      }
    

    If using the symfony_mailer_bc submodule and provided user mails (for example contact mails, this breaks).

    Error: [] operator not supported for strings in user_mail() (line 795 of core/modules/user/user.module).

    This because the body is predefined to a string in this patch, while it should be an array for the user_module. However this does then conflict again in reroute_email.

    The website encountered an unexpected error. Please try again later.
    TypeError: nl2br(): Argument #1 ($string) must be of type string, array given in nl2br() (line 500 of modules/contrib/reroute_email/reroute_email.module).
    nl2br(Array) (Line: 500)
    reroute_email_mailer_post_render(Object)
    

    No solution yet IMO, just posting here for people to get a heads up.

  • πŸ‡ΊπŸ‡ΈUnited States shelane

    I ended up going with a module that was written from the ground up specifically for Symfony mailer. https://www.drupal.org/project/symfony_mailer_reroute β†’

    It’s been working great.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Using reroute_email in combination with symfony_mailer and it simply works! What am I doing wrong? :D

  • First commit to issue fork.
  • @abyss opened merge request.
  • πŸ‡ΊπŸ‡¦Ukraine abyss

    Here we need to update the functionality to the 2.3.x branch.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine

    Hi @Abyss,
    a brand new 2.3.x branch has been created for the version of the module with RerouteEmailHandler plugins.

    Here is a meta issue for Drupal Symfony Mailer support:
    [#3391109[

    Here is a todo list on this issue:
    - we need to change MR destination branch to 2.3.x;
    - actually, merge 2.3.x into your branch;
    - a create a new RerouteEmailHandler plugin for Drupal Symfony Mailer support;
    - remove all reroute logic from EmailAdjuster, it should only inject `plugin.manager.reroute_email_handler` and properly call `$reroute_handlers_manager->processAllByType("symfony_mailer_adjuster", $email);`

  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine

    All changes for initial support of Symfony Mailer:
    - added EmailAdjuste/RerouteEmailAdjuster plugin;
    - added RerouteEmailHandler/SymfonyMailerAdjuster plugin;
    - refactored SettingsForm to be re-usable;
    are committed to a brand new 2.3.x branch (which is supposed to be a branch for all releases with Drupal Symfony Mailer support).
    No backport is expected here (for either 2.2.x or 2.1.x branches).

    All further work for Drupal Symfony Mailer support can be tracked here:
    πŸ“Œ [META] Drupal Symfony Mailer support Active

    Thanks, @all!

  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine
  • πŸ‡©πŸ‡ͺGermany Grevil

    Great Stuff! Thanks a lot!! πŸ‘

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

Production build 0.71.5 2024