zytzagoo / smtp-validate-email

A PHP library for performing email addresses validation via SMTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All address at the same domain becomes invalid if the server responds with 421 4.7.0 Error: too many errors

orionstar opened this issue · comments

I'm doing batch validations for my mail lists (ten thousends addresses) . A few email provider gives me error like below with varying account status (inactive, deleted, blocked etc):
550 5.1.1 <PLACEHOLDER@freemail.hu>: Recipient address rejected: u'SMTP service is disabled for this account. AccountId: 12345678. Reason: The account is INACTIVE'
Unexpected response to RCPT TO: 550 5.1.1 <PLACEHOLDER@freemail.hu>: Recipient address rejected: u'SMTP service is disabled for this account. AccountId: 12345678. Reason: The account is INACTIVE'
(I've changed the mailbox name to placeholder)

After errors like this all address at the same domain becomes invalid even if I got back 250 2.1.5 Ok for the most of them.

This problem only occurs if I'm validating large batches. If I only validate 50 or so the issue doesn't occur.

Ok, so what does the code on php side look like for that?
Especially the part which is (supposedly?) using this library?

I'm basically using the sample code without customization:
$validator = new SmtpEmailValidator($emails, $sender); $results = $validator->validate();

The $emails array contains 20 to 50 thousands of addresses when I'm facing the issue, the $sender is my company's email address. When I started to debug then I enabled the debug property by setting it true.

Could be related to "catch-all" and/or no_comm_is_valid settings/handling ? (see catchall_is_valid property: https://github.com/zytzagoo/smtp-validate-email/blob/master/src/Validator.php#L41) and the logic inside performSmtpDance() (https://github.com/zytzagoo/smtp-validate-email/blob/master/src/Validator.php#L391)

Could you maybe produce a reduced example that reproduces the issue reliably?
(amount of emails should not matter as such, same bug should be reproducible with 2-3 recipients on the same domain)

A bit off topic. How many emails should we validate at the same time?

Now I had time to dig deeper. The last error is always 421 4.7.0 mx.onbox.hu Error: too many errors. If I have 20 failed address then this response triggered by some of the hosts and after that Validator.php::802 expect() throws UnexpectedResponseException beacuse of the error code (421) then its catched in line 360 and it sets all address as invalid inspite of previous successfull checks. I assume the expect() method should be refactored by throwing a new ReconnectNeededException if it encounters with 421 4.7.0 then it should be catched in the address foreach (line 342) and reconnect if it happens.

Example set:
$addresses = [ 'asd123456781@freemail.hu', 'asd123456782@freemail.hu', 'asd123456783@freemail.hu', 'asd123456784@freemail.hu', 'asd123456785@freemail.hu', 'asd123456786@freemail.hu', 'asd123456787@freemail.hu', 'asd123456788@freemail.hu', 'asd123456789@freemail.hu', 'asd1234567810@freemail.hu', 'asd1234567811@freemail.hu', 'asd1234567812@freemail.hu', 'asd1234567813@freemail.hu', 'asd1234567814@freemail.hu', 'asd1234567815@freemail.hu', 'info@freemail.hu', 'asd123456712@freemail.hu', 'asd123456722@freemail.hu', 'asd123456732@freemail.hu', 'asd123456742@freemail.hu', 'asd123456752@freemail.hu', ];

If you delete one of the made up mail address then the validation will work correctly.

In my case I limited my batches to max 20 addresses at these providers as a hotfix.

Thank you for your assistance. Merry Xmas! ;)