Search code examples
emaildelphisslgmailindy

Cannot send email (via GMail) with Indy. Protocol version mismatch


I want to send an email via GMail server.

  TRY
    SMTP.Connect;      // <---- This is TIdSMTP
  EXCEPT
    Log.AddError('Cannot connect to the email server.');
  END;

  if SMTP.Connected then
   TRY
     SMTP.Send(MailMessage);
   EXCEPT
     on E:Exception DO
      begin
       Log.AddError('Connected to server but could not send email!');
       Log.AddError(E.Message);
      end;
   END;

 if SMTP.Connected
 then SMTP.Disconnect;

This piece of code worked in 2014 with Delphi XE.

The program connects to the server ok but in the end it says "SSL is not available on this server":

Resolving hostname smtp.Gmail.com.
Connecting to 74.125.xxx.xxx
Connected.
Connected to SMTP server...
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 hello A"
Disconnected.
Connected to server but could not send email!  
SSL is not available on this server.  

I have the latest version of OpenSSL (downloaded today) and Delphi XE7.
The WireShark says:

Alert (Level: Fatal, Description: Protocol version)

Why I cannot send email?
I have tried all: no TSL, implicit, explicit, startTSL...

enter image description here


Solution

  • SOLUTION: sslvTLSv1 must be included in the SSLIOHandler.SSLVersions property.