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