Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending email to 365 server
#1
Here is an extract code I am using/testing that keeps returning the error: 'Socket Error # 10060'#$D#$A'Connection timed out.'

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  idSMTP1: TIdSMTP;
  idSASLLogin: TIdSASLLogin;
  idUserPassProvider: TIdUserPassProvider;
begin
  idSMTP1 := TIdSMTP.Create(nil);
  try
    idSMTP1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idSMTP1);
    idSMTP1.UseTLS := utUseExplicitTLS;
    TIdSSLIOHandlerSocketOpenSSL(idSMTP1.IOHandler).SSLOptions.SSLVersions := [sslvTLSv1_2];

    idSMTP1.Host := 'smtp.office365.com';
    idSMTP1.Port := 587;

    idSASLLogin := TIdSASLLogin.Create(idSMTP1);
    idUserPassProvider := TIdUserPassProvider.Create(idSASLLogin);

    idSASLLogin.UserPassProvider := idUserPassProvider;
    idUserPassProvider.Username := 'XXXXXX';
    idUserPassProvider.Password := 'YYYYYY';

    idSMTP1.AuthType := satSASL;
    idSMTP1.SASLMechanisms.Add.SASL := idSASLLogin;

    try
      idSMTP1.Connect;
      try
        idSMTP1.Authenticate;
      finally
        idSMTP1.Disconnect;
      end;
      ShowMessage('OK');
    except
      on E: Exception do
      begin
        ShowMessage(Format('Failed!'#13'[%s] %s', [E.ClassName, E.Message]));
        raise;
      end;
    end;
  finally
    idSMTP1.Free;
  end;

end;

Can someone please help by pointing to what/where I going wrong

TIA
Reply


Messages In This Thread
Sending email to 365 server - by zsleo - 04-22-2020, 06:43 AM
RE: Sending email to 365 server - by rlebeau - 04-22-2020, 05:50 PM
RE: Sending email to 365 server - by zsleo - 04-22-2020, 11:07 PM
RE: Sending email to 365 server - by rlebeau - 04-23-2020, 12:53 AM
RE: Sending email to 365 server - by zsleo - 04-24-2020, 04:21 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)