I've been working a bit now on a little project to implement a simple blacklist for Magento CE 1.9.x and Aschroder's SMTPPro email extension. I've been in a couple of different directions with this, at first thinking that I was going to have to override getTemplateSubject()
, and potentially some other methods, in order to intercept an outgoing email, as I don't believe that (sans-SMTPPro) Magento has any events that fire on dispatching of an email. As a sidenote, corrections on any misconceptions that I may be having in this posting are very much appreciated.
So I've gone ahead and focused on tying in to SMTPPro's aschroder_smtppro_before_send
event to try to fire my code. I want to eventually check the recipient address, look for a substring, and can any emails matching that criteria (potentially with a message to an admin) at some point in the future. Right now, however, I can't even get the code to give me a var_dump
just to know that it's even firing. I did try tying the code to a different event, at one point (namely controller_action_predispatch
, which broke the site in the way that I was betting on), but I'm not sure where that leaves me for what is going wrong right now. Unless the documentation I've seen is incorrect and SMTPPro doesn't have the event defined or firing.
So here is what I've done.
in $INST_HOME/app/code/local/Myorganization I've created the tree:
drwxrwsr-x 3 dgetsman src 4096 Jul 1 03:38 Core.bak drwxrwsr-x 2 scriptuser src 4096 Jul 2 20:57 etc drwxrwsr-x 2 scriptuser src 4096 Jul 1 01:24 Helper drwxrwsr-x 2 dgetsman src 4096 Jul 2 20:42 Model
Emailblacklist/Core.bak: total 4 drwxrwsr-x 2 dgetsman src 4096 Jul 2 20:30 Model
Emailblacklist/Core.bak/Model: total 4 -rw-rw-r-- 1 dgetsman src 921 Jul 1 03:41 Email.php
Emailblacklist/etc: total 4 -rw-rw-r-- 1 scriptuser src 998 Jul 2 20:57 config.xml
Emailblacklist/Helper: total 4 -rw-rw-r-- 1 scriptuser src 86 Jul 1 01:24 Data.php
Emailblacklist/Model: total 4 -rw-rw-r-- 1 dgetsman src 201 Jul 2 02:05 Observer.php
Please note that Core.bak only includes some vestigial code that I was working on from when I was still attempting to go about this via overriding the getTemplateSubject()
method.
Contents of Emailblacklist/etc/config.xml follow:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Myorganization_Emailblacklist>
<version>0.1.0</version>
</Myorganization_Emailblacklist>
</modules>
<global>
<helpers>
<emailblacklist>
<class>Myorganization_Emailblacklist_Helper</class>
</emailblacklist>
</helpers>
<models>
<myorganization_emailblacklist>
<class>Myorganization_Emailblacklist_Model</class>
</myorganization_emailblacklist>
</models>
<events>
<!-- for debugging purposes
<controller_action_predispatch> -->
<aschroder_smtppro_before_send>
<observers>
<myorganization_emailblacklist>
<class>myorganization_emailblacklist/observer</class>
<method>watchEmails</method>
</myorganization_emailblacklist>
</observers>
</aschroder_smtppro_before_send>
<!-- debugging: </controller_action_predispatch> -->
</events>
</global>
</config>
Contents of Emailblacklist/Helper/Data.php follow:
<?php
class Uselite_Emailblacklist_Helper_Data extends Mage_Core_Helper_Abstract {
}
Contents of Emailblacklist/Model/Observer.php follow:
<?php
class Uselite_Emailblacklist_Model_Observer {
public function watchEmails(Varien_Event_Observer $observer) {
$order = $observer->getEvent();
die(var_dump($order));
}
}
As can be assumed from the aforementioned code, I'm hoping at this point just to get a dump of $order
at this point. Absolutely anything helpful will be very much appreciated. Thanks for your time and consideration. Please also feel free to let me know if I've forgotten to include any information that will be helpful to the troubleshooting process here.