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
- Ensure that you have Delphi installed on your system.
- You have set up your codebase to use the Indy library.
- You have created and verified your domain on AhaSend.
- You have created SMTP credentials (username and password) for authentication.
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