Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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;

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow