magento2 – Warning: fwrite(): SSL: Broken pipe when sending mails from Magento messaging queue

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 {

        $sender = (
            'name' => $this->escaper->escapeHtml($data('sender_name')),
            'email' => $this->escaper->escapeHtml($data('sender_email')),

        $transport = $this->transportBuilder
                    'area' => MagentoFrameworkAppArea::AREA_FRONTEND,
                    'store' => $this->storeManager->getStore()->getId()



        return true;
    } catch (Exception $e) {

    return false;

We are using Magento enterprise 2.3.3, any help would be appreciated.