Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Create, save, and reopen a plain-text email
See more Email Object Examples
Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.
Chilkat Lazarus Pascal 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.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
received: TEmail;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
email.From := 'Sam Lee <sam@example.com>';
success := email.AddTo('Alex Rivera','alex@example.net');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
email.Subject := 'Hello';
email.Body := 'This is a plain-text message.';
success := email.SaveEml('message.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
received := TEmail.Create;
success := received.LoadEml('message.eml');
if (success <> True) then
begin
WriteLn(received.LastErrorText);
Exit;
end;
WriteLn(received.From);
WriteLn(received.Subject);
WriteLn(received.GetPlainTextBody());
email.Free;
received.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.