Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Quickly Send a Simple Email
See more SMTP Examples
Demonstrates the Chilkat MailMan.QuickSend method, which sends a simple email to a single recipient without requiring the application to create an Email object. The arguments are the from address, the to address, the subject, the body, and the SMTP server hostname. This example sends a plain-text message in one call.
Background:
QuickSend is a convenience for the most common case: one plain-text message to one recipient. It skips the build-an-Email-object step, so it's ideal for quick notifications and alerts. When you need more — HTML bodies, attachments, multiple recipients, Cc/Bcc, or custom headers — build an Email object and use SendEmail instead. Authentication settings still come from the MailMan properties.Chilkat Pascal (Lazarus/Delphi) Downloads
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;
begin
success := False;
// Demonstrates the MailMan.QuickSend method, which sends a simple email to a single
// recipient without requiring the application to create an Email object. The arguments are
// the from address, the to address, the subject, the body, and the SMTP server hostname.
mailman := TMailMan.Create;
// SMTP authentication settings (the SMTP server hostname is passed to QuickSend).
mailman.SmtpPort := 465;
mailman.SmtpSsl := True;
mailman.SmtpUsername := 'user@example.com';
mailman.SmtpPassword := 'myPassword';
// Send a simple email in one call.
success := mailman.QuickSend('alice@example.com','bob@example.com','Quick hello','This is a quick message.','smtp.example.com');
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
WriteLn('Email sent.');
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
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.