Link to home
Start Free TrialLog in
Avatar of dcrudo
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(telnet.LastCmdResult.NumericCode));
       memo1.Lines.Add(telnet.LastCmdResult.Text.CommaText);
          if (telnet.LastCmdResult.NumericCode = 250) then
             begin
              label3.Caption := 'Email is valid';
             end;
          if (telnet.LastCmdResult.NumericCode = 550) then
             begin
              label3.Caption := 'Email is NOT valid';
             end;
          if (telnet.LastCmdResult.NumericCode <> 250) and
             (telnet.LastCmdResult.NumericCode <> 550) then
             begin
               label3.Caption := 'Error code: ' + IntToStr(telnet.LastCmdResult.NumericCode);
             end;
       telnet.Disconnect(False);

 except
  on E : Exception do
    Begin
     memo1.Lines.Add(E.ClassName + ' : ' + E.Message);
         label3.Caption := 'Error code: ' + E.Message;
     telnet.Disconnect(True);
    end;
 end;
Avatar of MerijnB
MerijnB
Flag of Netherlands image

at what place in your code do you get this exception or the freeze?
Avatar of dcrudo
dcrudo

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...
are you always using the same SMTP server?
Avatar of dcrudo

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)
freezes could simply mean the smtp server is down or very busy...
Avatar of dcrudo

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
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin