Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Apr : Re: connect to mailserver with TidTelnet, LastCmdResult

www.cryer.info
Managed Newsgroup Archive

Re: connect to mailserver with TidTelnet, LastCmdResult

Subject:Re: connect to mailserver with TidTelnet, LastCmdResult
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Mon, 16 Apr 2007 14:34:49

"Peter Gustafsson" <sm5triATpassagenDOTse> wrote in message
news:4623e895$1@newsgroups.borland.com...

> I have change the code again. I use TidSMTP now. But this
> simple code doesn't work:

Because you are still using it wrong.  Don't call SendCmd() or
GetResponse() at all now.  TIdSMTP handles that for you automatically.
All you have to do is Connect() and Disconnect(), and Send() your
messages when needed.  If you want to know the commands that TIdSMTP
sends internally, then attach a TIdLog... component, such as
TIdLogEvent, to TIdSMTP's Intercept property before connecting to the
server.

> SMTP.Connect;
> SMTP.GetResponse(220);
>
> It freeze on GetResponse.

As it should be.  Connect() did all of the handshaking internally, so
there is no pending command for GetResponse() to receive the reply to.
So it waits for data that the server will never send.

>         TCPClient.sendCmd('DATA');

You are not checking the server's response code to make sure that the
command actually succeeded.

>         TCPClient.sendCmd('From: A <testing@testing.se>' + #13);
>         TCPClient.sendCmd('To: B <testing@testing.se>' + #13);
>         TCPClient.sendCmd('Subject: testing' + #13);
>         TCPClient.sendCmd('Testmessage');

That is completely wrong.  DO NOT use SendCmd() to send the individual
lines of the message!  Those are not real commands, so they will not
have any responses for SendCmd() to receive.  Use WriteLn() instead
(making sure to escapsing any starting periods on each line - or else
put the message into a TStrings and use WriteRFCStrings() instead).

Otherwise, just use the TIdSMTP.Send() method instead, and let it
handle the DATA command for you.

> The only respond I get is when DATA is send.

That is because that is the only response being sent back to begin
with.


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive