Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Verify SMTP Login (Connect and Authenticate)

See more SMTP Examples

Demonstrates the Chilkat MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect to the configured SMTP server and successfully authenticate using the current SMTP authentication settings. This example configures the SMTP host and credentials and verifies login.

Background: This goes one step further than VerifySmtpConnection: after reaching the server it also performs the AUTH exchange with your username and password (or OAuth2 token). It's the ideal preflight check when validating credentials or diagnosing "why won't my mail send?" — a false result after a good connection points squarely at bad credentials or an unsupported auth method rather than a network problem.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.MailMan;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  mailman: TMailMan;
  loggedIn: Boolean;

begin
  success := False;

  //  Demonstrates the MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect
  //  to the configured SMTP server and successfully authenticate using the current SMTP
  //  authentication settings.

  mailman := TMailMan.Create;

  //  Configure the SMTP server connection.
  mailman.SmtpHost := 'smtp.example.com';
  mailman.SmtpPort := 465;
  mailman.SmtpSsl := True;
  mailman.SmtpUsername := 'user@example.com';
  mailman.SmtpPassword := 'myPassword';

  //  Test both connectivity and authentication.
  loggedIn := mailman.VerifySmtpLogin();

  if (loggedIn = True) then
    begin
      WriteLn('Successfully connected and authenticated with the SMTP server.');
    end
  else
    begin
      WriteLn('SMTP connect or login failed.');
    end;


  mailman.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.