Chapters Close

How does email queue work in Magento?

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 the checkout/post-checkout process error-free: Generally, sending orders and emails in bulk will certainly affect website performance and you don’t want that because eCommerce website performance matters a lot..
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 uncomfortably 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 a queue for smooth sending, then also it can be achieved by the solution presented below.

Send invoices using the 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.

Feel free to leave the comments below and contact us if you need any other help.

Speak your Mind

Post a Comment

Got a question? Have a feedback? Please feel free to leave your ideas, opinions, and questions in the comments section of our post! ❤️

* This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Grow your online business like 2,554 subscribers

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
    envelope

    Thank You!

    We are reviewing your submission, and will be in touch shortly.