Dmitry Savy
Dmitry Savy

Reputation: 1067

Indy SMTP hangs or freezes up on Connect method

I have a client attempting to connect SMTP server. I have the OnStatus event linked to the smtp client and see the

Resolving / Connecting / Connected states. But sometimes there is a hangup / application freezes when trying to connect. I see the Connected state being raised from OnStatus though. What could the issue be. I ruled out the Resolving DNS ans et both ConnectTimeout and Readtimeout settings on smtp as shown here:

  smtp.OnStatus := SMTPStatus;
  smtp.ConnectTimeout := 10000;
  smtp.ReadTimeout := 10000;
  smtp.Connect;
  // SOMETIMES MY LOG DOES NOT GET HERE Log('AfterConnect');
  if smtp.Connected then
  begin
    smtp.Send(Mess);
    smtp.Disconnect;
  end

On about 600KB attachment it seems to be getting stuck on encoding the attachment part and never completes, currently the encoding type is the default one.

10/3/2012 10:21:43 AM  Status: Resolving hostname XXXXXXXXXX.com.
10/3/2012 10:21:43 AM  Status: Connecting to 10.5.2.171.
10/3/2012 10:21:44 AM  Status: Connected.
10/3/2012 10:21:45 AM  Status: Encoding text
10/3/2012 10:21:45 AM  Status: Encoding attachment

Upvotes: 1

Views: 3040

Answers (2)

Mike Taylor
Mike Taylor

Reputation: 2524

Many SMTP server are configured to delay the initial greeting msg by 30 or so seconds to try and deter SPAM, Also most servers can be configured to reject connections from the same ip addresses if it has tried to connect multiple times within a specified time period (typically 1 Min). It could be this that is causing you issues.

Upvotes: 2

Remy Lebeau
Remy Lebeau

Reputation: 596256

If the OnStatus event is reporting hsConnected then you are physically connected to the server. If Connect() is not exiting afterwards then it is likely blocked waiting for data from the server that is not arriving, such as the server's initial Greeting. The ReadTimeout should be handling that possibility, though (unless you have an OnConnected event handler assigned that is becoming deadlocked, that is). Use a packet sniffer, such as Wireshark, to make sure that you are actually connecting to the server you are expecting and that it is sending the right kind of greeting data that TIdSMTP is expecting.

Upvotes: 2

Related Questions