This module doen't work with SymfonyMailer Module

Created on 11 May 2022, over 2 years ago
Updated 19 August 2023, about 1 year ago

PHP 8.0.17
D 9.3.12
Symfony mailer module is running
Queue mail installed via composer.

In Queue Mail setting page all mail IDs appear in the list of site emails (native ones & custom ones)
Mail IDs to queue is set to * (all emails)

cron set to 1hour

So far so good, but...

ISSUE 1:
Site is sending emails immediatly (not queued)
ISSUE 2:
In setting page I can read "1 mail currently queued for sending".
but in database the queue table is empty
If I click on "run cron manually" nothing appens (still "1 mail currently queued for sending")
ISSUE3:
I implemented the following in php script

 $mailManager = \Drupal::service('plugin.manager.mail');
            $mail= $mailManager->mail($module, $key, $to, $langcode, $params, $reply, $send);
                   
            if ($mail['queued']) {
                  \Drupal::logger('node2notifs')->notice('mail queued ');
                }
            else {
                  \Drupal::logger('node2notifs')->notice('mail NOT queued ');
                }

And I get an error Warning : Undefined array key "queued"

So at the end of the day queing is not working as expected.

Edit: 1 hour later I found the reason. Uninstall Symfony Mailer and IT WORKS!

💬 Support request
Status

Closed: won't fix

Version

1.4

Component

Miscellaneous

Created by

🇫🇷France gilbertdelyon

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.

  • 🇬🇧United Kingdom steven jones

    I think that the solution here is to get the async sending working in Drupal Symfony Mailer, which seems to want to have it's own API and do things in it's own way, outside of lots of the existing Drupal ecosystem for mail sending. so marking this as a 'won't fix'.

  • 🇳🇿New Zealand heathergaye

    Hey, I needed this working in a hurry, so I've written a quick & dirty patch for the queue_mail version 8.x-1.x.

    Queue worker just re-sends the email using the standard mail manager, and bypasses the queue_mail_mail_alter intercept by setting a flag in the message params.

    Purely for reference if anyone else needs this in a hurry; I expect the module authors had reasons not to do this.
    No guarantees, but it works for me.

  • Status changed to Active about 1 year ago
  • 🇨🇿Czech Republic parisek

    I found pretty good example how it could be implemented in this module (use EmailAdjuster) https://www.drupal.org/project/maillog/issues/3259616 Support Symfony Mailer RTBC

    I think it's unnecessary to create separate module for this feature.

  • 🇳🇴Norway hansfn

    I'm the maintainer of the Views Send module. (No, don't every copy code from it - it's vey messy.)

    My understanding is that MailManagerReplacement (and LegacyMailerHelper) should have made our old code work. However, there seems to be an issue that could explain the missing $mail['queued']: 🐛 Wrong return value for MailManagerReplacement::mail() Active . In addition, if you are queue by setting send to false, you are probably also affected by 🐛 MailManagerReplacement::mail() doesn't always compose Active .

    If these two are fixes, I think VS and QM should work with Symfony Mailer without any changes.

  • 🇦🇺Australia mustafa_abdalle

    I'm using Symfony Mailer + Queue Mail and when I send an email from my custom code (custom form) using:

    $mail= $mailManager->mail($module, $key, $to, $langcode, $params, $reply, $send);

    The queue mail cannot send the email and throws the error:

    sh: 1: /usr/sbin/sendmail: not found
     [error]  Error sending email (from <email address> to <email address> with <email address>). 

    I did not encounter this issue when I'm using the old Mail System + SwiftMailer + Queue Mail modules.

    Also, when I try to send a reset password and a test email while Symfony Mailer + Queue Mail modules are enabled, the emails are sent just fine.

    My Implementation:
    - Using SMTP Mail policy for Symfony Mailer
    - Custom Module that uses Drupal MailManager to send an email.
    - I have implemented hook_mail in my custom module.

    function MODULE_mail($key, &$message, $params) {
    	switch ($key) {
    		case 'custom_key':
    			$message['subject'] = $params['subject'];
    			$message['body'][] =	$params['body'];
    			$message['from'] = \Drupal::config('system.site')->get('mail');
    			break;
    		default:
    			$message['subject'] = 'Default';
    			$message['body'][] = 'Default Key';
    			$message['from'] = \Drupal::config('system.site')->get('mail');
    	}
    }
    
    

    is this related to Queue Mail not compatible yet with Symfony Mailer?

  • 🇳🇴Norway hansfn

    is this related to Queue Mail not compatible yet with Symfony Mailer?

    No, very unlikely since 1) you get the error about /usr/sbin/sendmail not found and 2) the reset password mail is sent. I guess your custom code is using another transport plugin (sendmail) than the reset password test. Create another issue if you need help.

  • 🇮🇹Italy plach Venezia

    FYI queue/async support for Symfony Mailer is being added at Add Symfony Messenger support for async messsages (emails as queues) Active .

  • 🇮🇳India omsingh89

    We are getting below error when an email is queued.
    Warning: Undefined array key "from" in Drupal\queue_mail\Plugin\QueueWorker\SendMailQueueWorker->processItem() (line 169 of \web\modules\contrib\queue_mail\src\Plugin\QueueWorker\SendMailQueueWorker.php)

    Steps to replicate:
    1. Write an custom hook_mail logic. for example:
    function my_module_mail($key, &$message, $params) {
    $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
    switch ($key) {
    case 'custom_notification':
    $message['subject'] = t($params['subject']);
    $message['body'] = [t($params['body'])];
    $message['from'] = \Drupal::config('system.site')->get('mail');
    break;
    }
    }
    2. Trigger email as per logic.
    3. Email will get queued and then run Cron to receive email.

    FYI, the error is around code written in patch #8
    + $message = $this->mailManager->mail(
    + $message['module'],
    + $message['key'],
    + $message['to'],
    + $message['langcode'],
    + $message['params'],
    + $message['from']
    + );

Production build 0.71.5 2024