We have to send multiple emails through Magento 2 messaging queue and for emails, we are using SendGrid SMTP, and the module used within Magento to integrate this is of Mageplaza.
When we start the queue, the first few emails send fine without any issue but after a few we receive:
Sendgrid SMTP connection timed out
After this, we start receiving the following error:
Warning: fwrite(): SSL: Broken pipe in vendor/zendframework/zend-mail/src/Protocol/AbstractProtocol.php on line 260
We have found this fix of the above error and override the Mageplaza SMTP module to apply this fix. This does fix the issue but now again after the first few emails, the emails are getting failed and we are getting the following error:
Cannot issue HELO to existing session
The method used to send emails is following:
public function sendEmail($data = null)
{
try {
$this->inlineTranslation->suspend();
$sender = [
'name' => $this->escaper->escapeHtml($data['sender_name']),
'email' => $this->escaper->escapeHtml($data['sender_email']),
];
$transport = $this->transportBuilder
->setTemplateIdentifier($data['email_template'])
->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($data['template_vars'])
->setFromByScope($sender)
->addTo($data['customer_email'])
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
return true;
} catch (\Exception $e) {
$this->logger->critical($e->getMessage());
}
return false;
}
We are using Magento enterprise 2.3.3, any help would be appreciated.