Indy 10 - IdSMTP.Send() hangs when sending messages from GMail account
Asked Answered
R

4

6

I am trying to send an e-mail using gmail account (Delphi 7, Indy 10) with these settings:

TIdSmtp:

Port = 587;
UseTLS := utUseExplicitTLS;

TIdSSLIOHandlerSocketOpenSSL:

SSLOptions.Method := sslvTLSv1;

Everything seems to be set ok. I get this response:

Resolving hostname smtp.gmail.com.
Connecting to 74.125.77.109.
SSL status: "before/connect initialization"
SSL status: "before/connect initialization"
SSL status: "SSLv3 write client hello A"
SSL status: "SSLv3 read server hello A"
SSL status: "SSLv3 read server certificate A"
SSL status: "SSLv3 read server done A"
SSL status: "SSLv3 write client key exchange A"
SSL status: "SSLv3 write change cipher spec A"
SSL status: "SSLv3 write finished A"
SSL status: "SSLv3 flush data"
SSL status: "SSLv3 read finished A"
SSL status: "SSL negotiation finished successfully"
SSL status: "SSL negotiation finished successfully"
Cipher: name = RC4-MD5; description = RC4-MD5                 SSLv3 Kx=RSA      Au=RSA  Enc=RC4(128)  Mac=MD5 
; bits = 128; version = TLSv1/SSLv3;

And then it hangs and doesn't finish. E-mail is not sent. What can be the problem?

Retiarius answered 27/1, 2010 at 8:51 Comment(0)
R
3

The problem was simple. I was not patient enough and application didn't hang, there was long timeout. The timeout was result of wrong settings.

Retiarius answered 17/3, 2010 at 13:18 Comment(0)
R
4

yes, i've seen lots of issues with indy10 and tls (generally gmail).

first make sure you have the latest ssl libraries from here

i've seen intermittent stalls and errors that have been resolved in the bleeding edge version of indy (ie. a non-stable release). see http://www.indyproject.org/sockets/download/svn.DE.aspx

for gmail, i generally use implicityTLS on port 465..

  idSmtp := TIdSMTP.Create(nil);
  try
    idSmtp.IOHandler := nil;
    idSmtp.ManagedIOHandler := true;

    // try to use SSL
    try
      TIdSSLContext.Create.Free;
      idSmtp.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idSmtp);
      if (smtpSettings.port = 465) then
        idSmtp.UseTLS := utUseImplicitTLS
      else
        idSmtp.UseTLS := utUseExplicitTLS;
    except
      idSmtp.IOHandler.Free;
      idSmtp.IOHandler := nil;
    end;

    if (idSmtp.IOHandler = nil) then
    begin
      idSmtp.IOHandler := TIdIOHandler.MakeDefaultIOHandler(idSmtp);
      idSmtp.UseTLS := utNoTLSSupport;
    end;

    // send message, etc

  finally
    idSmtp.Free;
  end;
Raoul answered 28/1, 2010 at 2:51 Comment(2)
Excellent! Your post helped me. My app also freezed during smtp.send. I think the key was utUseImplicitTLS option but i also don't understand what this TIdSSLContex.Create.Free does.Murine
TIdSSLContext.Create.Free creates an object and immediately frees it. It's there to trigger an exception if the TIdSSLContext object can't be created.Raoul
R
3

The problem was simple. I was not patient enough and application didn't hang, there was long timeout. The timeout was result of wrong settings.

Retiarius answered 17/3, 2010 at 13:18 Comment(0)
F
1

First off, have you verified the code is working with other email servers?

Some time ago someone mentioned they were having problems with certain servers accepting http requests with the Indy TIdHTTP component. The reason was they had Indy included as part of the useragent:

      Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';

When they removed Indy Library it worked. Evidently there have been some malignant web services created with Indy, so some sites will refuse connections from applications created with it.

I am not sure if the component you are using has any sort of UserAgent property. But if it does, null out any references to Indy.

Freed answered 27/1, 2010 at 15:56 Comment(2)
UserAgent is for HTTP requests, not SMTPRaoul
glob you are correct; I did conclude by saying "I am not sure if the component you are using has any sort of UserAgent property"Freed
H
1

When testing Indy, you should be sure that “Stop on Delphi Exceptions” is checked (Tools, Debugger Options, Language Exceptions).

Some routines, specifically idSMTP.Send, ‘eats’ (or hides) exceptions resulting in a hang up.

Hertahertberg answered 24/7, 2010 at 2:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.