Sends emails and retries failures not working for custom module emails

Created on 14 March 2025, 3 months ago

After installing and enabling Symfony Mailer Queue, I did:

  1. I updated General Cron Settings (I use Ultimate Cron): Override cron queue processing=Yes
  2. I changed Mailer policy: added 'Queue sending' to '*All* *All*'
  3. I used Mailer Test (see Capture 1)
  4. I ran cron 'Queue: Sends emails and retries failures' (see Capture 2)

And it works!

  1. I generated a bunch of emails with one custom module cron. The 'queue' table of my database is populated
  2. I ran cron 'Queue: Sends emails and retries failures'

And it doesn't work!
The log of the cron job says:
Error: Unknown named parameter $__disable_customize__ in Drupal\symfony_mailer\EmailFactory->initEmail() (line 92 of /var/www/html/web/modules/contrib/symfony_mailer/src/EmailFactory.php).

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

đŸ‡Ģ🇷France gbmapo

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

Merge Requests

Comments & Activities

  • Issue created by @gbmapo
  • 🇩đŸ‡ĒGermany simonbaese Berlin

    Thank you for the report. This is probably related to 🐛 Remove '__disable_customize__' parameters while queuing legacy emails Active . I will check it out soon once client work is less busy.

  • đŸ‡Ģ🇷France gbmapo

    I did another try after converting all my custom modules to use Level 3 Native implementation of Drupal Symfony Mailer.
    Everything works fine when I don't use Symfony Mailer Queue.

    When I use it, it doesn't â˜šī¸
    The log of the cron job (Queue: Sends emails and retries failures) says:

    Warning: Undefined array key 0 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams() (line 37 of /var/www/html/web/modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php) @backtrace_string.
    Warning: Undefined array key 1 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams() (line 45 of /var/www/html/web/modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php) @backtrace_string.
    TypeError: Drupal\symfony_mailer\MailerHelper::parseAddress(): Argument #1 ($encoded) must be of type string, null given, called in /var/www/html/web/modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php on line 72 in Drupal\symfony_mailer\MailerHelper->parseAddress() (line 101 of /var/www/html/web/modules/contrib/symfony_mailer/src/MailerHelper.php).
    

    The good thing is that the correct EmailBuilder is called.
    The problem is that the parameters of the email aren't sent from the queue.
    Sorry, I couldn't debug further...

  • đŸ‡Ģ🇷France gbmapo

    I tried again after upgrading Drupal Symfony Mailer to 1.6.0.
    I still have the errors related to EmailBuilder not getting the emails parameters.

    Warning: Undefined array key 0 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams() (line 37 of modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php).
    Warning: Undefined array key 1 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams() (line 41 of modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php).
    Warning: Undefined array key 2 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams() (line 42 of modules/custom/amap/src/Plugin/EmailBuilder/EmailBuilder.php).
  • đŸ‡Ģ🇷France gbmapo

    I tried to debug a little and here are my findings:

    In my custom module, I send emails with:

    $emailFactory = \Drupal::service('email_factory');
    $sTo = $user->getEmail();
    $email = $emailFactory->newTypedEmail('amap', $key, $sTo, $sNextWednesday, $D);
    
    

    In my EmailBuilder, I have

      public function createParams(EmailInterface $email, ...$myParams) {
      $email->setParam('to', $myParams[0]);
      $email->setParam('distributiondate', $myParams[1]);
      $email->setParam('numberofamapiens', $myParams[2]);
      }
    

    and it works fine when emails are sent directly (not with Symfony Mailer Queue) because in createParams() of EmailBuilder, $myParams is equal to

    Array
    (
        [0] => abc@free.fr
        [1] => 4 juin 2025
        [2] => 2
    )

    If I sent the same emails with Symfony Mailer Queue, when I run the cron job 'Queue: Sends emails and retries failures', I get the errors I mentioned previously [Undefined array key 0 in Drupal\amap\Plugin\EmailBuilder\EmailBuilder->createParams()], because at that point, $myParams is equal to

    Array
    (
        [to] => eric.falzon@free.fr
        [distributiondate] => 4 juin 2025
        [numberofamapiens] => 2
    )

    I understand that the error is coming from the difference of the keys ot the array $myParams in the two cases.

    I know that I can update my EmailBuilder to handle this, but my question is:
    Why doesn't Symfony Mailer Queue return exactly what it has in input, (an array with keys 0, 1, 2, ... in this case)?

  • 🇩đŸ‡ĒGermany simonbaese Berlin

    @gbmapo Thank you for the detailed report and the additional findings from your investigation. This is very helpful to understand the problem.

    The Symfony Mailer module alters the email parameters, not the Symfony Mailer Queue module. Yet, the queue worker sends the email through the processing of Symfony Mailer again. To circumvent problems with altered parameters, we now reinitialize the email in the queue worker with the original parameters.

    Can you please check whether this solves your issues? Additionally, could you please review the code changes?

  • đŸ‡Ģ🇷France gbmapo

    I patched my installed version of Symfony Mailer Queue with your changes in your merge request !2 and rerun my set of tests.
    I'm glad to announce that it works!
    Thanks a lot.

  • 🇩đŸ‡ĒGermany simonbaese Berlin
  • 🇩đŸ‡ĒGermany simonbaese Berlin
  • Pipeline finished with Skipped
    2 days ago
    #515714
  • 🇩đŸ‡ĒGermany simonbaese Berlin

    @gbmapo Thanks again for the support. The changes will be part of the next minor release. Please use the 1.2.x development branch until then.

Production build 0.71.5 2024