Archived Forum Post

Index of archived forum posts

Question:

Several socket send-receive cycles (the second fails)

Nov 13 '12 at 00:36

I`m trying to develop email verification algorithm. So my algorithm is the following (for example we try to verify admin@kolchaka.net):

=========== Lookup for:admin@kolchaka.net MX:mail.kolchaka.net MX:mail.kolchaka.net

21:22:43 284 Begin check address <admin@kolchaka.net> on mail host: mail.kolchaka.net 21:22:43 284 Lookup 21:22:43 288 Connecting to mail.kolchaka.net... 21:22:43 386 Connected to host: cp12.eskhosting.com 21:22:43 407 < 220 cp12.eskhosting.com ESMTP Postfix

21:22:43 408 > HELO KOLCHAKA-PC 21:22:43 479 < 250 cp12.eskhosting.com

21:22:43 479 > MAIL FROM:<> 21:22:43 558 < 250 2.1.0 Ok

21:22:43 558 > RCPT TO:<admin@kolchaka.net> 21:22:43 654 < 554 5.7.1 <admin@kolchaka.net>: Relay access denied

21:22:43 654 > RSET 21:22:43 753 < 250 2.0.0 Ok

21:22:43 753 > QUIT 21:22:43 846 < 221 2.0.0 Bye

21:22:43 848 Disconnected from host: cp12.eskhosting.com

===========

I try to create this algorithm with the following code:

===========================

public Chilkat.MailMan mailman = new Chilkat.MailMan(); public Chilkat.Socket socket = new Chilkat.Socket();

mailman.UnlockComponent("30-day trial"); socket.UnlockComponent("30-day trial"); // Set maximum timeouts for reading an writing (in millisec) socket.MaxReadIdleMs = 30000; socket.MaxSendIdleMs = 30000;

#region get MX string mailServerHostname = mailman.MxLookup(email);

if (mailServerHostname == null || mailServerHostname == "") { nonexistingReason = "MX not found"; return false; }

#endregion

#region establish connection

// Connect to the server: bool success = socket.Connect(mailServerHostname, 25,false, 20000);

if (!success) { lastError = socket.LastErrorText; return false; } #endregion

#region HELO

success = socket.SendString("HELO KOLCHAKA-PC"); if (!success) { lastError = socket.LastErrorText; return false; }

receivedMsg = socket.ReceiveString(); if (receivedMsg == null) { lastError = socket.LastErrorText; return false;

}

if(receivedMsg.IndexOf("220")!=0) { lastError = "receivedMsg.IndexOf(220)=0"; return false; }

#endregion

#region MAIL FROM

success = socket.SendString("MAIL FROM:<isolar2005@gmail.com>");

if (!success) { lastError = socket.LastErrorText; return false; }

receivedMsg = socket.ReceiveString(); if (receivedMsg == null) { lastError = socket.LastErrorText; return false;

}

if (receivedMsg.IndexOf("2") != 0) { lastError = "receivedMsg.IndexOf(2)=0"; return false; } /**/ #endregion

#region RCPT TO

success = socket.SendString(" RCPT TO:<"+email+">"); if (!success) { lastError = socket.LastErrorText; return false; }

receivedMsg = socket.ReceiveString(); if (receivedMsg == null) { lastError = socket.LastErrorText; return false;

}

if (receivedMsg.IndexOf("225") != 0) { lastError = "receivedMsg.IndexOf(225)=0"; return false; }

#endregion

#region Close connection

socket.Close(10000);

#endregion

================

The problem is that after I do first cycle of SendString and ReceiveString, I cannot receive the next command reply. In the above code I just get NULL in the result of the MAIL FROM block (I mean here receivedMsg = socket.ReceiveString();). At the same time HELO block works completely fine - because SendString and ReceiveString are used the first time there.

#region MAIL FROM

success = socket.SendString("MAIL FROM:<isolar2005@gmail.com>");

if (!success) { lastError = socket.LastErrorText; return false; }

receivedMsg = socket.ReceiveString(); if (receivedMsg == null) { lastError = socket.LastErrorText; return false;

}

if (receivedMsg.IndexOf("2") != 0) { lastError = "receivedMsg.IndexOf(2)=0"; return false; } /**/ #endregion

====================

So what am I doing wrong (I was trying several HELO commands and got the same result - first was working out and the second one returned null. If I close and open connection between commands the problem disappears, but in that case it makes no sense, because commands need to be sent during one connection).