Question

Roughly 2-3 out of hundreds of Windows 8 clients began getting this message 2-3 weeks ago.

per Wireshark the last transmission before the connection is closed is

'2.0.0 Ready to start TLS'

Code snippet:

Smtp := TIdSMTP.Create(nil);
try
  IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(smtp);
  try
    Smtp.OnStatus := IdSMTP1Status;
    Smtp.OnWorkBegin := IdSMTP1WorkBegin;
    Smtp.OnWorkEnd := IdSMTP1WorkEnd;
    Smtp.OnWork := IdSMTPWork;
    Smtp.Host := 'smtp.gmail.com'
    Smtp.Port := 487, 565 both tried here;
    Smtp.Username := 'the email@gmail.com'
    Smtp.Password := 'The password'
    // TLS for Gmail, etc
    if UseSSL then // true 
    begin
      Smtp.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
      if Smtp.Port = 465 then
        Smtp.UseTLS := utUseImplicitTLS
      else
      if Smtp.Port = 587 then
        Smtp.UseTLS := utUseExplicitTLS
      else
        Smtp.UseTLS := utUseExplicitTLS;
      IdSSLIOHandlerSocketOpenSSL1.Host := 'gmail smtp again'

      IdSSLIOHandlerSocketOpenSSL1.Destination :=
        Smtp.Host + ':' + IntToStr(Smtp.Port);
      IdSSLIOHandlerSocketOpenSSL1.Port := Smtp.Port;
    end;
    try
     Smtp.Connect;
     sTempFileName := data1.GetSettingsFileFolder+'\tmp.email';
     EmailMessage.SaveToFile(sTempFileName);
     AssignFile(F,sTempFileName);
     Reset(F);
     iFileSize := FileSize(F) * 128;
     CloseFile(F);
     SysUtils.DeleteFile(sTempFileName);
     StatusForm.SetProgress(0,iFileSize);
     Smtp.Send(EmailMessage);
    except on E:Exception do
      begin
        MessageDlg(E.Message, mtError, [mbOK], 0);
        Exit;
      end;
    end;
  finally
    IdSSLIOHandlerSocketOpenSSL1.Free;
  end;
finally
  EmailMessage.MessageParts.Clear;
  if Smtp.Connected then smtp.Disconnect;
  Smtp.Free;
end;
Was it helpful?

Solution

2.0.0 Ready to start TLS is sent in reply to a STARTTLS command. If you are getting disconnected immediately afterwards, then the TLS handshake is likely failing, and you should be getting an exception explaining why it failed. Double-check your TLS settings. Also keep in mind that setting the UseTLS property may change the Port property, so it is best to set UseTLS before setting Port rather than the other way around.

Also, You do not need to set the IOHandler's Host, Port, or Destination properties. Connect() will handle that for you.

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