zytzagoo / smtp-validate-email

A PHP library for performing email addresses validation via SMTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need MAIL FROM before RCPT TO

hostbox2 opened this issue · comments

Fatal error: Uncaught SMTPValidateEmail\Exceptions\NoMailFrom: Need MAIL FROM before RCPT TO

   $sender = 'myemail@domain.com';
    $unknown_email = 'ogmetr2@psmural.ru';
    $unknown_email = trim($unknown_email);
    if (!empty($unknown_email)) {
        var_dump($unknown_email);
        $validator = new SmtpEmailValidator($unknown_email, $sender);
        $result = $validator->validate();
        var_dump($result);
        $log = $validator->getLog(); var_dump($log);
        if ($result[$unknown_email]) {
            file_put_contents ('valid_emails.txt', $unknown_email."\n", FILE_APPEND);
        }
        else {
            file_put_contents ('invalid_emails.txt', $unknown_email."\n", FILE_APPEND);
        }
    }

Other check the mailing address handles correctly without error. Only this email gives an error.

Here is the debug output:

array (size=1)
'domains' =>
array (size=1)
'psmural.ru' =>
array (size=2)
'users' =>
array (size=1)
0 => string 'ogmetr2' (length=7)
'mxs' =>
array (size=2)
'mail.psmural.ru' => int 10
'psmural.ru' => int 0
array (size=29)
0 => string '[2019-05-20T14:15:39.460138+0000] MX records (psmural.ru): Array
(
[mail.psmural.ru] => 10
[psmural.ru] => 0
)
' (length=119)
1 => string '[2019-05-20T14:15:39.460251+0000] Connecting to mail.psmural.ru:25' (length=66)
2 => string '[2019-05-20T14:15:39.523915+0000] Connected to mail.psmural.ru:25 successfully' (length=78)
3 => string '[2019-05-20T14:15:39.657394+0000] <<<recv: 220 mail.psmural.ru Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Mon, 20 May 2019 19:17:33 +0500
' (length=160)
4 => string '[2019-05-20T14:15:39.657503+0000] send>>>: EHLO domain.com' (length=60)
5 => string '[2019-05-20T14:15:44.930552+0000] <<<recv: 250-mail.psmural.ru Hello [217.114.12.86]
' (length=86)
6 => string '[2019-05-20T14:15:44.930776+0000] <<<recv: 250-TURN
' (length=53)
7 => string '[2019-05-20T14:15:44.930947+0000] <<<recv: 250-SIZE
' (length=53)
8 => string '[2019-05-20T14:15:44.931099+0000] <<<recv: 250-ETRN
' (length=53)
9 => string '[2019-05-20T14:15:44.931254+0000] <<<recv: 250-PIPELINING
' (length=59)
10 => string '[2019-05-20T14:15:44.931396+0000] <<<recv: 250-DSN
' (length=52)
11 => string '[2019-05-20T14:15:44.931546+0000] <<<recv: 250-ENHANCEDSTATUSCODES
' (length=68)
12 => string '[2019-05-20T14:15:44.931673+0000] <<<recv: 250-8bitmime
' (length=57)
13 => string '[2019-05-20T14:15:44.931757+0000] <<<recv: 250-BINARYMIME
' (length=59)
14 => string '[2019-05-20T14:15:44.931835+0000] <<<recv: 250-CHUNKING
' (length=57)
15 => string '[2019-05-20T14:15:44.931911+0000] <<<recv: 250-VRFY
' (length=53)
16 => string '[2019-05-20T14:15:44.931998+0000] <<<recv: 250-X-EXPS GSSAPI NTLM LOGIN
' (length=73)
17 => string '[2019-05-20T14:15:44.932075+0000] <<<recv: 250-X-EXPS=LOGIN
' (length=61)
18 => string '[2019-05-20T14:15:44.932153+0000] <<<recv: 250-AUTH GSSAPI NTLM LOGIN
' (length=71)
19 => string '[2019-05-20T14:15:44.932230+0000] <<<recv: 250-AUTH=LOGIN
' (length=59)
20 => string '[2019-05-20T14:15:44.932307+0000] <<<recv: 250-X-LINK2STATE
' (length=61)
21 => string '[2019-05-20T14:15:44.932385+0000] <<<recv: 250-XEXCH50
' (length=56)
22 => string '[2019-05-20T14:15:44.932468+0000] <<<recv: 250 OK
' (length=51)
23 => string '[2019-05-20T14:15:44.932574+0000] send>>>: MAIL FROM:myemail@domain.com' (length=74)
24 => string '[2019-05-20T14:15:44.995840+0000] <<<recv: 250 2.1.0 myemail@domain.com....Sender OK
' (length=87)
25 => string '[2019-05-20T14:15:44.996020+0000] send>>>: NOOP' (length=47)
26 => string '[2019-05-20T14:15:45.049014+0000] <<<recv: ' (length=43)
27 => string '[2019-05-20T14:15:45.050510+0000] No response in expect(): No response in recv' (length=78)
28 => string '[2019-05-20T14:15:45.050634+0000] Closing socket to mail.psmural.ru:25' (length=70)

Version: Latest commit 2b0e257 on Oct 31, 2018

Does this happen consistently, regardless of which machine you try to query their servers from?

Because, this is a caught exception in a pretty specific case:
https://github.com/zytzagoo/smtp-validate-email/blob/master/src/Validator.php#L843

Screen Shot 2019-05-21 at 10 17 24

The fatal error can maybe be avoided, since the actual cause in case of this specific server is that the server does not allow NOOP commands, and actually kills the connection when a second NOOP is attempted after the first one: (this is my debug log, slightly different from yours, who knows why...)

...
[2019-05-21T08:27:07.584384+0000] <<<recv: 250 OK

[2019-05-21T08:27:07.585328+0000] send>>>: MAIL FROM:<myemail@domain.com>
[2019-05-21T08:27:07.651797+0000] <<<recv: 250 2.1.0 myemail@domain.com....Sender OK

[2019-05-21T08:27:07.652530+0000] send>>>: NOOP
[2019-05-21T08:27:07.718555+0000] <<<recv: 500 Command not allowed

[2019-05-21T08:27:07.719367+0000] send>>>: NOOPPHP Notice:  fwrite(): send of 6 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.

So perhaps the NOOPs could be made optional, if it doesn't break any existing use cases... Not sure when I'll get around to have a chance at fully investigating this...

If you care to fix it on your end, you can try just removing the $this->noop(); calls (or better yet just insert an early return into the noop() method), and see if that helps you get rid of the fatal...

There's an option now in latest master that allows one to disable sending NOOP commands (along with tests for it confirming it works).

https://github.com/zytzagoo/smtp-validate-email/blob/master/src/Validator.php#L1191
https://github.com/zytzagoo/smtp-validate-email/blob/master/tests/Functional/ValidatorTest.php#L161

When/if that becomes a part of some official tag/release... no idea.