Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Build an AMP email with text and HTML fallbacks
See more Email Object Examples
Place text/x-amp-html inside multipart/alternative, before the regular HTML alternative. Use the AMP email validator and meet your provider’s sender requirements before using a dynamic campaign. AMP email MIME structure.
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.Mime,
Chilkat.BinData,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
mimeBytes: TBinData;
mime: TMime;
special: TMime;
standard: TMime;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
email.From := 'Workshop team <events@example.com>';
success := email.AddTo('Alex Rivera','alex@example.net');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
email.Subject := 'Workshop reminder';
email.Body := 'Your workshop starts at 09:00.';
mimeBytes := TBinData.Create;
success := email.GetMimeBd(mimeBytes);
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
mime := TMime.Create;
success := mime.LoadMimeBd(mimeBytes);
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
success := mime.ConvertToMultipartAlt();
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Append the specialist part before the standard HTML fallback.
special := TMime.Create;
special.ContentType := 'text/x-amp-html';
special.Charset := 'utf-8';
special.SetBody('<!doctype html><html amp4email><head><meta charset=''utf-8''><style amp4email-boilerplate>body{visibility:hidden}</style><script async src=''https://cdn.ampproject.org/v0.js''></script></head><body><p>Your workshop starts at 09:00.</p></body></html>');
success := mime.AppendPart(special);
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
standard := TMime.Create;
standard.ContentType := 'text/html';
standard.Charset := 'utf-8';
standard.SetBody('<p>Your workshop starts at <b>09:00</b>.</p>');
success := mime.AppendPart(standard);
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
success := mime.SaveMime('amp.eml');
if (success <> True) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Saved amp.eml.');
email.Free;
mimeBytes.Free;
mime.Free;
special.Free;
standard.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.