ikkez / f3-mailer

Fat-Free Sugar Mailer Plugin
GNU General Public License v3.0
18 stars 2 forks source link

Too many open connections #8

Open YoeriNijs opened 5 months ago

YoeriNijs commented 5 months ago

The mail plugin causes problems when sending emails in bulk. I use AWS SES and have already adjusted the limits, so AWS should not throw any errors here. However, I still receive smtp errors. It seems that the open connections are not being closed properly.

The error I get: SMTP dialog error: 421 Throttling failure: Too many open connection from Account. Try again later.

I call the F3 mailer by creating an instance and send a mail for every recipient, by doing so:

foreach($recipients as $r) {
   $mailer = new Mailer();
   $mailer->addTo($recipient, null);
   ...
   $mailer->send();
}

The number of recipients in my case is +/- 400. I suspect F3 is not closing the connection properly, but just want to make sure it is not the F3 mailer as well.

slavino commented 5 months ago

You would need to dive deeper into debugging and check whether similar commands are being executed - referring to "quit" and eventually "close" from PHP Mailer .

https://github.com/PHPMailer/PHPMailer/blob/829def33886c827e1622f965a8813d7bf453f15a/src/SMTP.php#L936

https://github.com/PHPMailer/PHPMailer/blob/829def33886c827e1622f965a8813d7bf453f15a/src/SMTP.php#L705

YoeriNijs commented 5 months ago

According to the stacktrace, the real problem is in F3's SMTP handler:

Wed, 08 May 2024 10:01:27 +0200 [x.x.x.x] <url />: 256, 500: SMTP dialog error: 421 Throttling failure: Too many open connection from Account. Try again later.

Wed, 08 May 2024 10:01:27 +0200 [x.x.x.x] ([/var/www/html/vendor/bcosca/fatfree-core/smtp.php:162] [/var/www/html/vendor/bcosca/fatfree-core/smtp.php:237] SMTP->dialog() [/

So, if I understand correctly, if the SMTP return code is not 235, it should send the QUIT dialog and also close the socket connection. It seems that some conditions are not met when we loop for multiple recipients?

YoeriNijs commented 5 months ago

Fyi: made the migration to PHPMailer and now the issue is resolved (also by closing the connection after every call).