zytzagoo / smtp-validate-email

A PHP library for performing email addresses validation via SMTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

recv: 550 IP blacklisted by Spamhaus

tobiascapin opened this issue · comments

I'm receiving a 550 error from SMTP due to spamhaus blacklist, this is not really an invalid mail error beause the email address was not given yet but I received a 550 error! This error is thrown just after the connection.
Is it possible somehow ignore this errors?

[2021-05-17T15:53:02.318087+0000] Connecting to smtp-in.libero.it:25


[2021-05-17T15:53:02.359458+0000] Connected to smtp-in.libero.it:25 successfully


[2021-05-17T15:53:02.360149+0000] <<<recv: 550 smtp-26.iol.local smtp-26.iol.local IP blacklisted by Spamhaus, https://www.spamhaus.org/query/ip/79.50.186.118  [smtp-26.iol.local; LIB_101]


[2021-05-17T15:53:02.374261+0000] Unexpected response after connecting: 550 smtp-26.iol.local smtp-26.iol.local IP blacklisted by Spamhaus, https://www.spamhaus.org/query/ip/79.50.186.118  [smtp-26.iol.local; LIB_101]


[2021-05-17T15:53:02.374288+0000] Closing socket to smtp-in.libero.it:25

Depends on what you mean by "ignore"...

There is an option no_comm_is_valid which controls whether not being able to talk to a server "means" email is valid or not:
https://github.com/zytzagoo/smtp-validate-email/blob/master/src/Validator.php#L401

Sample test:

public function testNoCommIsValidWithLocalSmtpRejectingOurSender()

What's your no_comm_is_valid option set to?

Another solution could perhaps be to extend the Validator class on your own and overwrite/change the way performSmtpDance() method works? That way you could do whatever you think is best for your use case...

no_comm_is_valid is set to true, but it was not enought.
I have to change a bit the helo response:

    protected function attemptMailCommands($domain, array $users)
    {
        // Bail if HELO doesn't go through...
        if (!$this->helo()) {
            $this->setDomainResults($users, $domain, $this->no_comm_is_valid);
            return;
        }

Because that server fails the transaction before the MAIL FROM command.
Adding $this->setDomainResults($users, $domain, $this->no_comm_is_valid); after the helo failure it uses the no_comm_is_valid setting and force a valid response.

What do you think?
Many thanks.

You should be able to do that in "userland", no?

Maybe something like:

<?php

namespace Whatever\You\Need;

use \SMTPValidateEmail\Validator;

class MyModifiedValidator extends Validator
{
    protected function attemptMailCommands($domain, array $users)
    {
        // Bail if HELO doesn't go through...
        if (!$this->helo()) {
            $this->setDomainResults($users, $domain, $this->no_comm_is_valid);
            return;
        }
        
        // ... (copy over rest of original attemptMailCommands() method
    }
}

And then in your existing calling code just load your custom Whatever\You\Need\MyModifiedValidator class.
You should be able to autoload custom/extra classes using composer.json easy.
So then "just" use your new custom class instead of the original Validator?

Something like:

<?php

use Whatever\You\Need\MyModifiedValidator as Validator;

// Your existing calling code here...

Did not try it myself fully, this is just a quick idea, but sounds like it could work...

Yes this is an idea, thanks.
I wrote this issue here just as suggestion to improve the compatibility, maybe this server behaviour is not so rare.
Thanks

If you're up for creating a pull request to modify the behavior, go for it - just make sure existing tests pass (and/or modify/add them to cover the new behavior) and we can probably merge it (and release, with a version bump and a changelog entry etc, since this is technically a somewhat breaking change for existing consumers)