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!

Comments

gilbertdelyon created an issue. See original summary.

gilbertdelyon’s picture

Issue summary: View changes
gilbertdelyon’s picture

Title: Does this module works with D9 ? » This module doen't work with SymfonyMailer
Issue summary: View changes
sinn’s picture

gilbertdelyon’s picture

Title: This module doen't work with SymfonyMailer » This module doen't work with SymfonyMailer Module
Issue summary: View changes
gilbertdelyon’s picture

Finally I uninstalled Symfony Mailer and did it on the "good old way":
Mail System + Swift Mailer + Queue Mail modules
And it works!( HTML, SMTP and queing)

I read that Swift Mailer will not be maintained in favour of Symfony Mailer.
I hope Queue mail will be compatible with Symfony Mailer in near future.

steven jones’s picture

Status: Active » Closed (won't fix)

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'.

heathergaye’s picture

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.

parisek’s picture

Title: This module doen't work with SymfonyMailer Module » Support SymfonyMailer Module
Version: 8.x-1.4 » 8.x-1.x-dev
Component: Miscellaneous » Code
Category: Support request » Feature request
Status: Closed (won't fix) » Active

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

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

hansfn’s picture

Title: Support SymfonyMailer Module » Support Symfony Mailer module

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']: #3400070: Wrong return value for MailManagerReplacement::mail(). In addition, if you are queue by setting send to false, you are probably also affected by #3394575: MailManagerReplacement::mail() doesn't always compose .

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

mustafa_ab’s picture

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?

hansfn’s picture

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.

plach’s picture

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

omsingh89’s picture

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']
+ );