6

I have some code that does an email address validation. It works by attempting a mail delivery via SMTP and then quitting without sending anything. It works most of the time, but in some fringe cases it does not. I have one of these cases and I would like to know if anyone has a clue as to what the mail server might be unhappy about in my request?

Here is the TCP session on port 25 to smtp.hp.com (I have substituted real email addresses here)

220-g1t6210.austin.hp.com ESMTP Postfix
HELO ednasmtp.beweb.co.nz
250 g1t6210.austin.hp.com
MAIL FROM: <a_real_email@beweb.co.nz>
250 2.1.0 Ok
RCPT TO: <a_real_hp_user_email@hp.com>
550 5.5.1 Protocol error
QUIT
550 5.5.1 Protocol error

My question is, why is HP's postfix server saying "Protocol error"? Isn't my mail delivery valid?

mike nelson
  • 216
  • 2
  • 7

3 Answers3

7

smtp.hp.com resolves to 4 different IP addresses. Each of them responds to SMTP, but they are configured in different ways. Without knowing which of the 4 you connected to it is difficult to say exactly why it failed. But I can go over your session step by step and explain multiple errors made by the client side along the way.

220-g1t6210.austin.hp.com ESMTP Postfix

This is a partial status message from the server as indicated by the -. The last line of the status will have a in that location. 3 of the 4 SMTP servers responds with a 2-line status message this way with a delay between the two lines. One of them responds with a 1-line status message, which rules out that one as having handled your session. The client will need to keep reading the status message until it has seen it all.

HELO ednasmtp.beweb.co.nz

At this point the client violates the protocol by sending a command before receiving the full status.

250 g1t6210.austin.hp.com

Here the server violates the protocol by sending a different status code in what a standards compliant client would interpret as continuation of the 220- status line from above.

MAIL FROM: <a_real_email@beweb.co.nz>

Here the client violates the protocol by the extraneous space between : and <. A space is never permitted in that location, though there exist mail servers which will ignore that space and allow the transaction to continue.

250 2.1.0 Ok
RCPT TO: <a_real_hp_user_email@hp.com>

Here the client violates the protocol again in the same way as in the MAIL command.

550 5.5.1 Protocol error

It's correct that there was a protocol error. It's hard to tell which of the protocol errors mentioned above it is complaining about. The RCPT command itself is erroneous, but it suffers from no error which haven't been seen earlier in the transaction as well.

QUIT
550 5.5.1 Protocol error

At this point it is hard to guess which side closed the connection. And given that both sides have violated the protocol it's probably no longer important. We can't even be sure which status codes applies to which commands.

kasperd
  • 30,455
  • 17
  • 76
  • 124
  • 5
    YES! The issue was indeed with the continuation statuses, with the dashes. I am now reading in a loop until I get to the non-dash status and everything works smoothly. – mike nelson Apr 23 '18 at 07:24
  • Very helpful, Thanks. – Jaskaran Singh Sep 20 '19 at 12:45
  • @mikenelson Can you explain please how did you fixed this? I am using the same PHP script. – George George Mar 30 '21 at 05:44
  • @GeorgeGeorge, sure. I am not using a PHP script, but your code needs to check for status continuation which looks like this: "220-" rather than "220 ". If it does not get 3 digits and then a space as the first chars of a line, then it must read another line. – mike nelson Mar 30 '21 at 18:21
3

Your host is failing a number of verifications that could be expected from an email server:

  • It fails rDNS validation for the name presented above.
  • It has no SPF record (a simple "v=spf1 a -all" policy would be appropriate".
  • The sending domain has no DKIM or DMARC record.

If you are doing address validation, you may be triggering any number of spam avoidance techniques. While in the past address validation was generally permitted, spammers have resulted validation being restricted. Fixing the items above may help but I wouldn't count on it.

These days the only widely supported address validation is to send an email with a validation link for the user to confirm their address.

You may want to review the canonical posts on email and postfix.

BillThor
  • 27,737
  • 3
  • 37
  • 69
  • I control the sending domain (beweb.co.nz) which does have correct SPF records. Do you mean HP.com's mail server? This could be any mail server on the internet, which is out of my control. We are only sending to it, and I am pretty sure it accepts mail from all over the internet. – mike nelson Apr 23 '18 at 07:04
  • @mikenelson I mean the server itself which you are identifying as ednasmtp.beweb.co.nz (rather than the name that passes rDNS. It should have an SPF record for itself as shown. – BillThor Apr 23 '18 at 22:34
  • @mikenelson From the accepted answer, it looks like you are writing your own SMTP code. There are libraries that do SMTP for most languages. The libraries are usually RFC compliant, where it appears your code was not. – BillThor Apr 23 '18 at 22:39
-1

Simplified answer: We need to wait for a few seconds, more lines will be displayed and then we will be able to helo .. as usual.

$ ncat 1.2.3.4 25
helo localhost
[..wait for a few seconds..and it works]

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 03 '22 at 10:37
  • woah, I edited it – Smile.Hunter Aug 04 '22 at 10:13