How email queue works in Magento?

By: Ananth Iyer, Apr 2nd, 2018 # Email # Magento

Magento Order Email
After Magento 1.9 edition and so, the order confirmation emails aren’t sent quickly. Instead, they are queued up to be sent with the Cron job operation. And with that update, let me put a question in front of you,

Why are Order emails send through the queue, while Invoice emails are sent directly?

Here, it is a list of reasons behind sending the orders email using the queue:
  • To make checkout/post-checkout process error-free: Generally, sending orders emails in bulk will certainly affect website performance and make eStore operations sluggish.
  • To avoid website slowdown: It is benefited by the re-send functionality in case of any failure or interruption.
  • To resend, if not delivered: Organised and queued flow of orders emails can avoid uncomfortability while processing for checkout or even after it.
However, Order’s email can also be sent immediately, without queueing up.

Send order email immediately:

If  you like to send order email immediately you can consider overriding the Mage_Sales_Model_Order::queueNewOrderEmail()  method by changing the following lines:
/** @var $emailQueue Mage_Core_Model_Email_Queue */
$emailQueue = Mage::getModel('core/email_queue');
$emailQueue->setEntityId($this->getId())
	->setEntityType(self::ENTITY)
	->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
	->setIsForceCheck(!$forceMode);
$mailer->setQueue($emailQueue)->send();
To:
/** @var $emailQueue Mage_Core_Model_Email_Queue */
$mailer->send();
If you want to send invoices using queue for smooth sending, then also it can be achieved by solution presented below.

Send invoices using queue:

The opposite solution is to let invoices use the queue: You must override Mage_Sales_Model_Order_Invoice::sendEmail  changing:
// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId); $mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
	'order' => $order,
	'invoice' => $this,
	'comment' => $comment,
	'billing' => $order->getBillingAddress(),
	'payment_html' => $paymentBlockHtml
	)
);
$mailer->send();
To:
// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
	'order' => $order,
	'invoice' => $this,
	'comment' => $comment,
	'billing' => $order->getBillingAddress(),
	'payment_html' => $paymentBlockHtml
	)
);
$emailQueue = Mage::getModel('core/email_queue');
$emailQueue->setEntityId($this->getId())
	->setEntityType('order_invoice')
	->setEventType('new_invoice');
$mailer->setQueue($emailQueue)->send();
Hence, these are some code manipulation by which you can send orders email quick or queue up invoice emails against immediate delivery. Hope it helps!