For a B2E project, we needed a way for a 1.9.X Magento shop to define, that mail to a particular domain (e.g.. @ keinemails.com) should not be sent.
Since we SMTP-Pro-Extension have of ASchroder in use, was it to adapt close this, to obtain the desired result.
In the first step we take the app / code / local / Aschroder / SMTPPro / Model / Email / template.php
Here we add before
/** * Send mail to recipient
and behind
class Aschroder_SMTPPro_Model_Email_Template extends Mage_Core_Model_Email_Template {
folgenden Code ein
protected $_avoidedDomains = array('keinemails.com', 'auchkeinemails.com'); protected function isPreventForDomain($email, $domains) { foreach ($domains as $domain) { $pos = strpos($email, $domain, strlen($email) - strlen($domain)); if ($pos === false) continue; if ($pos == 0 || $email[(int) $pos - 1] == "@" || $email[(int) $pos - 1] == ".") return true; } return false; }
further behind
public function send($email, $name = null, array $variables = array()) {
and before
$_helper = Mage::helper('smtppro');
this code
$emails = array_values((array)$email); $= array sentEmails();
finally by
$_helper = Mage::helper('smtppro');
yet this code
foreach($emails as $emailValue){ if($this->isPreventForDomain($email value, $this->_avoidedDomains)){ Magus::log(sprintf("We do not send email to %s", $email value), false, 'not_sent_email.log', true); continue; } $sentEmails[] = $ Email value; } if(count($sentEmails) == 0) return false; $emails = $sentEmails;
So, that we all together have the following
class Aschroder_SMTPPro_Model_Email_Template extends Mage_Core_Model_Email_Template { protected $_avoidedDomains = array('keinemails.com', 'auchkeinemails.com'); protected function isPreventForDomain($email, $domains) { foreach ($domains as $domain) { $pos = strpos($email, $domain, strlen($email) - strlen($domain)); if ($pos === false) continue; if ($pos == 0 || $email[(int) $pos - 1] == "@" || $email[(int) $pos - 1] == ".") return true; } return false; } /** * Send mail to recipient * * @param array|string $email E-mail(s) * @param array|string|null $name receiver name(s) * @param array $variables template variables * @return boolean **/ public function send($email, $name = null, array $variables = array()) { $emails = array_values((array)$email); $= array sentEmails(); $_helper = Mage::helper('smtppro'); foreach($emails as $emailValue){ if($this->isPreventForDomain($email value, $this->_avoidedDomains)){ Magus::log(sprintf("We do not send email to %s", $email value), false, 'not_sent_email.log', true); continue; } $sentEmails[] = $ Email value; } if(count($sentEmails) == 0) return false; $emails = $sentEmails; // If it's not enabled, just return the parent result. if (!$_helper->isEnabled()) { $_helper->log('SMTP Pro is not enabled, fall back to parent class'); return parent::send($email, $name, $variables); } // As per parent class - except addition of before and after send events
In our case, we have defined two domains. This can of course only be a.
We create this way a log file (/var/log/not_sent_email.log) – Here you can see which mail addresses were rejected when.
Used in Magento Version 1.9 Comments? Additions? Notes? Gladly!