Magento capture all emails
-
04-10-2020 - |
Question
I'd like to capture all email events in Magento before they're sent and prevent magento from sending them.
I know I can disable all emails under system > mail sending settings
, but this is not enough. I want to send data from that email to another system.
Something like this:
- Magento wants to send email
- Some method captures the email
- Same method prevents magento from sending the email
- Same method sends data through api to another system
How can I achieve this?
Solution
I dont know about the enterprise edition
but I am pretty sure that there is no event in ce
You can achieve this functionality by rewriting this classes
Mage_Core_Model_Email_Template
and Mage_Core_Model_Email
In both class you find send
method you need to rewrite the send method. as below
public function send($email, $name = null, array $variables = array())
{
Mage::dispatchEvent('email_template_send_before', array('email' => $this, 'email_to' => $email));
$return = parent::send($email, $name, $variables);
Mage::dispatchEvent('email_template_send_after', array('email' => $this, 'email_to' => $email));
return $return;
}
after rewrite this way now you have two events
email_template_send_before
and email_template_send_after
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange