Sample code for 30+ languages & platforms
Lazarus Pascal

Amazon SES SMTP: Send email over implicit TLS on port 465

See more Amazon SES Examples

Connect to the regional SES SMTP endpoint with TLS from the start of the connection. Load the SMTP username and password from protected application configuration. SES SMTP passwords are Region-specific and differ from AWS secret access keys used to sign API requests. Replace the From address with a verified sender. The example delivers to the SES mailbox simulator.

TLS connections to SES SMTP · Obtain SMTP credentials

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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,
  Chilkat.Email;

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

procedure RunDemo;
var
  success: Boolean;
  mail: TMailMan;
  email: TEmail;

begin
  success := False;

  //  Assumes Chilkat is unlocked. See Global Unlock Sample.

  success := False;

  mail := TMailMan.Create;
  //  Use the SMTP endpoint and SMTP credentials issued for the same AWS Region.
  mail.SmtpHost := 'email-smtp.us-west-2.amazonaws.com';
  mail.SmtpPort := 465;
  mail.SmtpSsl := True;
  mail.RequireSslCertVerify := True;
  mail.SmtpUsername := 'SES_SMTP_USERNAME';
  mail.SmtpPassword := 'SES_SMTP_PASSWORD';

  email := TEmail.Create;
  email.From := 'sender+reports@example.com';
  email.Subject := 'SES SMTP connection test';
  email.Body := 'This message was submitted over implicit TLS on port 465.';
  success := email.AddTo('SES mailbox simulator','success@simulator.amazonses.com');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  success := mail.SendEmail(email);
  if (success <> True) then
    begin
      WriteLn(mail.LastErrorText);
      Exit;
    end;
  WriteLn('SES accepted the message over SMTP.');
  success := mail.CloseSmtpConnection();
  if (success <> True) then
    begin
      //  The server already accepted the message. Retrying here could send a duplicate.
      WriteLn('The SMTP connection did not close cleanly.');
    end;


  mail.Free;
  email.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.