Sending emails using SMTP in Delphi


SMTP in Delphi

You can use the networking library Indy for sending emails in Delphi. 

Shout out to Kirk for providing the code samples!

Prerequisites

Sending emails using Indy TIdSMTP component

Code sample:

// Example Block: Using Indy Components (TIdSMTP)
begin
  smtp.IOHandler := IdSSL_ahasend;
  (smtp.IOHandler as TIdSSLIOHandlerSocketOpenSSL).PassThrough := False;
  smtp.Username  := '{username}';
  smtp.Password  := '{password}';
  smtp.host      := 'send.ahasend.com';
  smtp.port      := 587;
  smtp.AuthType  := satNone;
  smtp.UseTLS    := utUseExplicitTLS;
  smtp.UseEhlo   := true;
  IdMsg          := CreateMessage();
 
  smtp.Connect;
  try
  if smtp.Authenticate then  // Authenticate does the TLS handshake
  begin
     smtp.SendCmd('AUTH PLAIN '+IdEncoderMIME1.EncodeString(#0+smtp.Username+#0+smtp.Password));
     smtp.send(IdMsg);
  end;  
  finally
    smtp.Disconnect;
    IdMsg.Free;
  end;
end;

Replace {username} and {password} with your actual SMTP credential username and password from the Credentials page in your account.

Category
AhaSend
Send up to 1,000 emails per month on us, no credit card required!