Error when send massive emails (using silverstripe-newsletter module)
thinh2010 opened this issue · 3 comments
Hi, I got the problem that when I send a newsletter for 1000 emails, if in these emails has a bad email (such as: example@gmail.con), the smtp will throw the error to said that the sender is invalid. And then it cannot send any email.
I make some test and found that when the loop got the bad email, the next email send action is always throw this error:
The following From address failed: <my_email>
I tried with close the smtp every time it got error but not success
try {
$this->buildBasicMail($to, $from, $subject);
$customheaders['X-SMTPAPI'] = '{"category": "' . $_SERVER['HTTP_HOST'] . '"}'; // Add the current domain for services like SendGrid
$this->addCustomHeaders($customheaders);
$this->attachFiles($attachedFiles);
$this->mailer->Send();
if($this->mailer->SMTPDebug > 0){
echo "<em><strong>*** E-mail to $to has been sent.</strong></em><br />";
echo "<em><strong>*** The debug mode blocked the process</strong> to avoid the url redirection. So the CC e-mail is not sent.</em>";
die();
}
} catch(phpmailerException $pe){
$this->handleError($pe->errorMessage(), $msgForLog);
$this->mailer->SmtpClose();
throw $pe;
} catch(Exception $e){
$this->handleError($e->getMessage(), $msgForLog);
$this->mailer->SmtpClose();
throw $e;
}
Could you please check the problem? Thanks.
Admittedly, this module has been in hibernation mode for years and I haven't used it for quite some time. So I'm afraid I won't find the necessary time to dig into this...
Loop $to
and run the best email validation regex you can find against it, prune invalid = resolved.
If you got invalid emails stored, well you need not look far for the one responsible :P
Nice, thanks for the easy solution :)