Mega Search
23.2 Million


Sign Up

Make a donation  
TIdSMTP->Connect hangs [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket

I'm trying to figure out why TIdSMTP never returns or throws an exception when calling Connect().
In my original project when I encountered the problem I used SSL. To dumb the problem down, I made a simple project with IdSMTP1 and Button1 on it. 
IdSMTP1 has server set to smtp.gmail.com, port set to 465, user name set to non-existing-address@gmail.com and password set to 123456.
onClick of the button called IdSMTP1->Connect();
I also processed onStatus events that produced Resolving, Connecting and Connected messages. Connected is the last message I received from it. Adding IdSSLIOHandlerSocketOpenSSL1 back into the mix does not solve the problem, the difference is that Resolving and Connecting messages would come from onStatus of ...OpenSSL1, connected would still come from IdSMTP1.

Why is it hanging?

Here is the text version of the form (with SSL)
{code}
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 306
  ClientWidth = 505
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 72
    Top = 152
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object IdSMTP1: TIdSMTP
    OnStatus = IdSMTP1Status
    IOHandler = IdSSLIOHandlerSocketOpenSSL1
    MailAgent = 'My App'
    UseEhlo = False
    AuthType = satNone
    Host = 'smtp.gmail.com'
    Password = '123456'
    Port = 465
    SASLMechanisms = <>
    Username = 'non-existing-address@gmail.com'
    ValidateAuthLoginCapability = False
    Left = 104
    Top = 72
  end
  object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL
    OnStatus = IdSSLIOHandlerSocketOpenSSL1Status
    Destination = 'smtp.gmail.com:465'
    Host = 'smtp.gmail.com'
    MaxLineAction = maException
    Port = 465
    DefaultPort = 0
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
    Left = 216
    Top = 72
  end
end
{code}

My code is
{code}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	IdSMTP1->Connect();
	MessageDlg("Opened", mtInformation, TMsgDlgButtons()<
Vote for best question.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 11:56 AM EST
From: Gennadiy Kiryukhin
 
Re: TIdSMTP->Connect hangs [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
> Gmail's port 465 requires implicit SSL, and so TIdSMTP.UseTLS must be set 
> to utUseImplicitTLS (which requires an SSL IOHandler assigned to TIdSMTP.IOHandler). 
>  If you DO NOT enable implicit SSL, TIdSMTP.Connect() will hang (unless you 
> assign a non-infinite timeout to TIdSMTP.ReadTimeout).  The reason for this 
> is because TIdSMTP.Connect() would be waiting for the server's SMTP greeting, 
> but the server would be waiting for the client's SSL handshake request.  
> That is a deadlock (unless a timeout is used).
> 

That did it!

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 1:28 PM EST
From: Gennadiy Kiryukhin
 
Re: TIdSMTP->Connect hangs [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}


>  If you DO NOT enable implicit SSL, TIdSMTP.Connect() will hang …

You get Connection Closed Gracefully after 10 minutes. :-) You are hung for those 10 minutes though.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 1:47 PM EST
From: quinn wildman