pankaj
pankaj

Reputation: 21

ZF2 uncaught exception on concurrent emails exceeds limit with SMTP server

ZF2 throws uncaught exception when i am trying to send multiple mail at the same time, using SMTP server.

After sending 5 emails it throws an exception:

Uncaught exception: "Could not read from host" from Zend\Mail\Protocol\AbstractProtocol

this comes after SMTP server sends an error:

Message submission rate for this client has exceeded the configured limit

since this is thrown when destructor is called i am not able to catch it in my script. Any suggestion how to catch this, in my script.

Upvotes: 0

Views: 220

Answers (1)

edigu
edigu

Reputation: 10099

There is nothing to do with Zend Framework 2 or any other library. The message from the mail service which you consuming is pretty clear: you're exceeding the rate limit.

Anyway, you have several options;

  • Never send lot of e-mails in a single while / for loop since you don't have a cool paid e-mail service which doesn't apply any rate limit to your account. (Paid or not almost every service like yours applies rate limits to prevent abusing. This is normal.)
  • Add a try {} catch() {} block in your script and when you exceed the limit, just stop, wait for a while and try again.
  • You may consider writing a cronjob and a CLI script to send X emails per minute.
  • Implementing a message queue an sending emails by consuming that queue (X emails at a time) would be better if you need to send thousands of emails.
  • Ask your mail service provider to increase limits.
  • Change your mail service provider if rates are still not enough.

Upvotes: 1

Related Questions