I have craft 3.7.11 with commerce 3.4.2 installed. The majority of site emails send correctly, but every few days, one order status change email fails. The prior emails for these orders send correctly, it is always on the same status change, a change to 'shipped' that triggers an email with tracking information. It happens for multiple customers/products/orders, but always this status change email, and only about 5% of the time. I've loaded the preview template for the email with the order in question, and there are no errors on the template. There is no complex twig in any of the email fields, just the order reference number in the subject line. Retrying the email in the queue always fails again.
I've looked at the queue logs and I'm not seeing anything to go on here.
I've gone through the craft documentation's check list for email failure and everything seems to be in order. Again, most of the emails for the site work fine, and 95% of the time, this status change email works fine as well and it doesn't seem to be an issue of the order data causing a template error.
I'm adding the stack trace from the queue log. The web.log doesn't have any errors in it from the time the email failed. Can anyone point me in the right direction from here?
2021-09-09 14:32:02 [-][-][-][info][craft\queue\QueueLogBehavior::beforeExec] [87238] Sending email for order #278405 (attempt: 1, pid: 2054167) - Started
2021-09-09 14:32:03 [-][-][-][error][craft\commerce\services\Emails::sendEmail] Commerce email “Shipping Confirmation” could not be sent for order “382b888”.
2021-09-09 14:32:03 [-][-][-][error][craft\queue\QueueLogBehavior::afterError] [87238] Sending email for order #278405 (attempt: 1, pid: 2054167) - Error (time: 0.355s): Commerce email “Shipping Confirmation” could not be sent for order “382b888”.
2021-09-09 14:32:03 [-][-][-][error][craft\commerce\errors\EmailException] craft\commerce\errors\EmailException: Commerce email “Shipping Confirmation” could not be sent for order “382b888”. in /var/www/[site]/vendor/craftcms/commerce/src/queue/jobs/SendEmail.php:54
Stack trace:
#0 /vendor/yiisoft/yii2-queue/src/Queue.php(246): craft\commerce\queue\jobs\SendEmail->execute(Object(craft\queue\Queue))
#1 /vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('87238', 'O:35:"craft\\com...', '300', '1')
#2 /vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('87238', 'O:35:"craft\\com...', '300', '1', '2054167')
#3 [internal function]: yii\queue\cli\Command->actionExec('87238', '300', '1', '2054167')
#4 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#6 /vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('exec', Array)
#7 /vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('exec', Array)
#8 /vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('queue/exec', Array)
#9 /vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('queue/exec', Array)
#10 /vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('queue/exec', Array)
#11 /vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
#12 /craft(23): yii\base\Application->run()
#13 {main}
execute()
method actually failed, we can only speculate—is there anything else in the 2–3 lines aboveStack trace:
?throw
on its own, so the failure mode is really generic (basically, "couldn't send"). What email provider are you using? It could be something as simple as it getting falsely flagged as spam and rejected by the SMTP server or API (i.e. due to something in the text, a URL, etc.).