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!
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | queue-mail-working-for-symfony-mailer.patch | 2.35 KB | heathergaye |
Comments
Comment #2
gilbertdelyon commentedComment #3
gilbertdelyon commentedComment #4
sinn commentedComment #5
gilbertdelyon commentedComment #6
gilbertdelyon commentedFinally 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.
Comment #7
steven jones commentedI 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'.
Comment #8
heathergaye commentedHey, 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.
Comment #9
parisekI 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.
Comment #10
hansfn commentedI'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.
Comment #11
mustafa_ab commentedI'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:
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_mailin my custom module.is this related to Queue Mail not compatible yet with Symfony Mailer?
Comment #12
hansfn commentedNo, 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.
Comment #13
plachFYI queue/async support for Symfony Mailer is being added at #3394123: Add Symfony Messenger support for async messsages (emails as queues).
Comment #14
omsingh89 commentedWe 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']
+ );