1

Utilizing Magento CE 1.9.x and Aschroder's SMTPPro:

I was wondering if anybody might be able to give me a recommendation on the best method for trying to implement an email blacklist (ie if any of an array's substrings match, nix the email to a log, but send nothing) utilizing Aschroder's SMTPPro for transactional emails.

I've already experimented a bit with the event/observer model, but after having dug through the data structures that I've been able to get my hands on, I'm not sure that this is the way to do anything more than tie in new functionality, as opposed to aborting existing functionality.

Since then I've progressed on to trying to override some of the SMTPPro functionality, to check for the blacklisted substrings in the data/objects available, such as in the following code (added to app/code/local/Aschroder/SMTPPro/Model/Email.php):

class Aschroder_SMTPPro_Model_Email extends Mage_Core_Model_Email {

    //property addition for blacklist implementation by dgetsman
    private $blacklist = array('damo.gets');
    private $ddebug = true;

     public function send() {

        try {
            $dlog = fopen("/tmp/d4m0log.log", "a");
            fwrite($dlog, "Logging successfully now (variable issue)\n");
            fclose($dlog);
        } catch (e) {}  //yeah I know best error handling in the world


        $_helper = Mage::helper('smtppro');

        // If it's not enabled, just return the parent result.
        if (!$_helper->isEnabled()) {
            return parent::send();
        }

        if (Mage::getStoreConfigFlag('system/smtp/disable')) {
            return $this;
        }

        //begin additions by dgetsman to implement email blacklist
        $to_whom = $this->getToEmail();
        foreach ($this->blacklist as $blist_entry) {
            if (strpos($blist_entry, $to_whom) !== false) {
                if ($this->ddebug) {
                    try {
                        $dlog = fopen("/tmp/d4m0log.log", "a");
                        fwrite($dlog, "Blocked email to " . $to_whom . "\n");
                        fclose($dlog);
                    } catch (e) {}
                }

                return $this;
            }
        }*/
        //end additions by dgetsman to implement email blacklist

I'm not really getting anything, including my debugging output out of this code right now when an order successfully goes through. The standard canned emails sure are still going through, though.

If anybody can point me in the least time intensive methods for handling a question like this, or pointers in the right direction, even just a few guideposts when I'm digging further with my google-fu, anything would be greatly appreciated.

Also, am I going about overriding objects entirely the wrong way for the Magento model here? If there's some more lower level tutorials that I should be looking at I'm grateful for references there, as well.

Thanks in advance!

-Damon

0

This should speed up your debugging if you aren't already.

Perhaps moving your code block higher up in the pasted code as to catch blocked emails sooner before other code blocks return?

There is also an observer declared in the same Model you are overriding

Mage::dispatchEvent('aschroder_smtppro_before_send', array(

you can use instead of a local/ code pool override.

| improve this answer | |
  • I was actually tying in using that specific event (as well as the ...template_before_send) event to try to tie in with the observer/event model. I tried traversing all of the data structures that I had access to (that I could tell) and still was unable to determine how to flag that this email shouldn't be sent or should be sent to a canned address. Pretty much the same problem I'm having in overriding the class, as well. Any suggestions – Damon Getsman Jul 27 '15 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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