dcrudo
asked on
TidTelnet to send SMTP Emails...freezing
Dear Experts,
We have a huge list of email adresses of our customers and we need to find out which email adresses are still valid and which are not before sending out informations.
to do this, the idea is to connect to the SMTP server, pass the RCPT TO command and depending on the answer of the server we will then know if the email is valid or not.
The problemi i have, using the Telnet Indy component, is that many times it freezes or it gets a message "gracefully disconnected" . I've put an AntiFreeze component but it doesn't help.
I'm not sure i'm using the correct way to read the result of the connection, or i should use some kind of event handler before trying to read the answer of the server...could you help?
the code i'm testing is the following (replaced original values with 'bogus')
telnet.Host := 'mailhost.domain.com';
Adomain := 'user@domain.com';
telnet.Port := 25;
telnet.ConnectTimeout := 2000;
telnet.ReadTimeout := 2000;
try
telnet.Connect;
telnet.SendCmd('ehlo bogus.net');
telnet.SendCmd('mail from: <mailings@bogus.net>');
telnet.SendCmd('rcpt to: <' + Adomain + '>');
telnet.SendCmd('quit');
memo1.Lines.Add(IntToStr(t elnet.Last CmdResult. NumericCod e));
memo1.Lines.Add(telnet.Las tCmdResult .Text.Comm aText);
if (telnet.LastCmdResult.Nume ricCode = 250) then
begin
label3.Caption := 'Email is valid';
end;
if (telnet.LastCmdResult.Nume ricCode = 550) then
begin
label3.Caption := 'Email is NOT valid';
end;
if (telnet.LastCmdResult.Nume ricCode <> 250) and
(telnet.LastCmdResult.Nume ricCode <> 550) then
begin
label3.Caption := 'Error code: ' + IntToStr(telnet.LastCmdRes ult.Numeri cCode);
end;
telnet.Disconnect(False);
except
on E : Exception do
Begin
memo1.Lines.Add(E.ClassNam e + ' : ' + E.Message);
label3.Caption := 'Error code: ' + E.Message;
telnet.Disconnect(True);
end;
end;
We have a huge list of email adresses of our customers and we need to find out which email adresses are still valid and which are not before sending out informations.
to do this, the idea is to connect to the SMTP server, pass the RCPT TO command and depending on the answer of the server we will then know if the email is valid or not.
The problemi i have, using the Telnet Indy component, is that many times it freezes or it gets a message "gracefully disconnected" . I've put an AntiFreeze component but it doesn't help.
I'm not sure i'm using the correct way to read the result of the connection, or i should use some kind of event handler before trying to read the answer of the server...could you help?
the code i'm testing is the following (replaced original values with 'bogus')
telnet.Host := 'mailhost.domain.com';
Adomain := 'user@domain.com';
telnet.Port := 25;
telnet.ConnectTimeout := 2000;
telnet.ReadTimeout := 2000;
try
telnet.Connect;
telnet.SendCmd('ehlo bogus.net');
telnet.SendCmd('mail from: <mailings@bogus.net>');
telnet.SendCmd('rcpt to: <' + Adomain + '>');
telnet.SendCmd('quit');
memo1.Lines.Add(IntToStr(t
memo1.Lines.Add(telnet.Las
if (telnet.LastCmdResult.Nume
begin
label3.Caption := 'Email is valid';
end;
if (telnet.LastCmdResult.Nume
begin
label3.Caption := 'Email is NOT valid';
end;
if (telnet.LastCmdResult.Nume
(telnet.LastCmdResult.Nume
begin
label3.Caption := 'Error code: ' + IntToStr(telnet.LastCmdRes
end;
telnet.Disconnect(False);
except
on E : Exception do
Begin
memo1.Lines.Add(E.ClassNam
label3.Caption := 'Error code: ' + E.Message;
telnet.Disconnect(True);
end;
end;
at what place in your code do you get this exception or the freeze?
ASKER
IT freezes not always at the same point...but ususalyl executing a command like:
telnet.SendCmd('ehlo bogus.net');
it looks like is waiting for an answer...or it get stuck...
telnet.SendCmd('ehlo bogus.net');
it looks like is waiting for an answer...or it get stuck...
are you always using the same SMTP server?
ASKER
Hi,
no...the smtp changes as i do a DNS lookup first... but i found this information that maybe has some hints...
http://groups.google.com/group/borland.public.delphi.internet.winsock/msg/96b09becc1840219
but it freezes stil...
(using the TidTCPClient)
no...the smtp changes as i do a DNS lookup first... but i found this information that maybe has some hints...
http://groups.google.com/group/borland.public.delphi.internet.winsock/msg/96b09becc1840219
but it freezes stil...
(using the TidTCPClient)
freezes could simply mean the smtp server is down or very busy...
ASKER
...if i query the same server manually...it works fine... i think there is something wrong with the use of the components...maybe there is away to wait for an answer... and even the timeout doesn't work...when this happen...even i set the timeout to 2000ms...it stays frozen...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin