"SSL negotiation failed" in Delphi 11 while using office356 smtp server

Viewed 65

I tried to send mail using office365 smtp server but i am getting error "SSL Negotiation Failed". I have the latest openssl dll files. So the host in that case is smtp.office365.com. I also tried a code sample from other post but with no success. Can you help me please ?

procedure TForm7.Button3Click(Sender: TObject);
var
  IdSMTPa: TIdSMTP;
  IdMessage1: TIdMessage;
  IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  IdSMTPa := TIdSMTP.Create(nil);
  try
    IdSMTPa.Host := 'smtp.office365.com';
    IdSMTPa.Port := 587;
    IdSMTPa.Username := 'mymail@mydomain.gr'; 
    IdSMTPa.Password := 'mypwd';
    IdSMTPa.AuthType := satDefault;

    // IO HANDLER Settings //
    IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdSMTPa);
    IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
    IdSSL.SSLOptions.Mode := sslmUnassigned;
    IdSSL.SSLOptions.VerifyMode := [];
    IdSSL.SSLOptions.VerifyDepth := 0;
    IdSMTPa.IOHandler := IdSSL;

    IdSMTPa.UseTLS := utUseExplicitTLS;

    IdMessage1 := TIdMessage.Create(nil);
    try
      IdMessage1.From.Address := 'mymail@mydomain.gr'; 
      IdMessage1.Recipients.EMailAddresses := 'user1@mydomain.gr';
      IdMessage1.CCList.EMailAddresses  := 'user1@mydomain.gr';
      IdMessage1.Subject := 'Test Email Subject';
      IdMessage1.Body.Add('Test Email Body');
      IdMessage1.Priority := mpHigh;

      try
        IdSMTPa.Connect();
        try
          IdSMTPa.Send(IdMessage1);
          ShowMessage('Email sent');
        finally
          IdSMTPa.Disconnect();
        end;
      except
        on e: Exception do
        begin
          ShowMessage('ERROR : '+e.Message);
        end;
      end;
    finally
      IdMessage1.Free;
    end;
  finally
    IdSMTPa.Free;
  end;

end;

0 Answers
Related