Validating email address via Shell

My email validation method, using the web site (https://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email), the forum post for iOS (https://forum.xojo.com/37137-validating-an-email-address/0#p311617) and a shell command, works with the nslookup -q=mx… command and receives the mail exchangers (e.g. the iCloud exchange below mx2.mail.icloud.com ). My problem is in the next telnet step:

Dim tempShell As New Shell tempShell.TimeOut = -1 tempShell.Execute("telnet mx2.mail.icloud.com 25 ;helo")
It seems to close the telnet connection before the ‘help’ command can begin, with the shell Result:

[quote]Trying 17.172.34.12…
Connected to mx2.mail.icloud.com.
Escape character is ‘^]’.
Connection closed by foreign host.[/quote]
I have tried placing the ‘helo’ shell command on the same line (as above) or on two, but the result is the same — I get logged out. It works if I open a Terminal window and enter the same commands. Is there a problem with telnetting from within a shell?

This problem occurs with my Outlook.com and host mail exchanges too.

I admit, I have not read through all the links you shared above, but I wonder: why not just use a socket? Telnet is not a particularly special protocol… all you appear to be trying to do is connect to port 25, send the helo command, and wait for a response. A standard socket should have no problem with this at all… Is there some specific reason you are going through the trouble of using a terminal for this?

No special reason for the Shell except that all other tests can be done with the shell. A socket may be the workaround needed.

Here is a quick example that connects to the host you have above on port 25, sends the ;helo command, and receives a response.

That was quick @Kimball Larsen, Thank you.

I’m getting the connection response:

but no response from the ‘helo’. I’ve tried setting a button that writes ‘helo’ to the socket, but it gets no response. Any clues?

I’ve tried a polling timer, displaying all connection results and a button to send the ‘helo’ command, but still to results from the helo. My changes are in a revised version:

http://www.webappdevelopments.com/downloads/SocketTelnetExample.zip

How odd. I’m trying it against my own mail server and getting the same situation: The initial greeting is received, but nothing thereafter. My server’s logs indicate that the socket is disconnecting… I’m trying to figure out why.

Ahh… pop an endOfLine at the end of your write() call on the socket.

i.e.: mySocket.write("HELO test" + endOfLine)

Still not seeing it with:

[code] mySocket.Address = “mx2.mail.icloud.com
mySocket.Port = 25

	mySocket.Connect
	'mySocket.write(";helo")
	mySocket.Write("HELO test" + EndOfLine)[/code]

Still just returns:

Have you tried any other mail servers? It is working just fine with my own mail server, though I have to use port 587 because it does not accept port 25 smtp requests unless you pass a bunch of security stuff as a validated sending mail server.

I note that the tutorial you are following is from back in 2009, when email was more of a wild west than it is now… in recent years servers have gotten a lot more security-conscious, and are much more persnickety about what they let connect and talk to them.

However, I also note that an interactive telnet session in the terminal works with the server you have listed at icloud.com… there are some differences between Telnet and straight TCP socket communication, but at the core SMTP is performed by following the specs in the latest RFC, which a generic TCP socket should be able to do with no problems.

I hear what you’re saying, but using Terminal actually works to Telnet to iCloud. I typed three commands into Terminal:

telnet mx2.mail.icloud.com 25 HELO hi quit
and got this:

How can I get a TCPSocket to do what Terminal can do?

Hi David,

At this point I’d pull out a packet sniffer and inspect the packets that are being sent by the telnet client and compare those to the packets being sent by your socket. I like CocoaPacketAnalyzer for doing this sort of thing, but WireShark is the big name and most capable.