2

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.

1 Answer 1

2

In Magento 1.9 transactional emails are scheduled and then sent from a cronjob, so you will never see the result of var_dump() unless you trigger the cron manually from shell. You can use Mage::log() instead to prove that your observer is triggered.

5
  • Thank you! I was wondering if a cron scenario might have something to do with that, but stopped considering it at some point awhile ago. Good to know! Commented Jul 3, 2015 at 1:30
  • Now that I've got logging actually turned on, and now that I've got things configured to dump via Mage::log(), I'm still not finding the dump that I'm looking for anywhere. I've tried some alteration of the tag in config.xml from myorganization_emailblacklist to myorganization_emailblacklist_model_observer, for instance (which someone else suggested) and it's still not changing anything, either. I am, however, seeing some unrelated stuff spewing into $APPHOME/var/log, though, so I know logging is now working. Any other ideas, perchance? Commented Jul 3, 2015 at 16:43
  • any suggestions on how to get cron.sh running manually from within the shell? I've been working with /bin/sh /server/public/myorganization/current/cron.sh, but it appears that something in the environment is preventing it from running properly. Lack of output is hindering diagnosis of this. I've tried it from within the root directory, within the $APPHOME directory, and the home that it normally executes in, AFAIK. Doesn't fire off an email, though the second I put it back in the standard cron all seems fine. Any suggestions on manual triggering? Commented Jul 4, 2015 at 16:24
  • For monitoring crons, I highly suggest using Aoe_Scheduler, one of the first extension I install in every store. It comes with a scheduler_cron.sh which is way more useful than the default cron.sh. Otherwise, you could run php cron.php -mdefault instead of cron.sh, this way you'll at least see some output Commented Jul 4, 2015 at 16:33
  • Though that (php command line) managed to get the email sent out to me, it still fails to produce any output. I guess it's time to look into that extension. :| Commented Jul 4, 2015 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.