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

拟墨画扇 提交于 2019-12-04 06:42:12

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;

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!