Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Render an Email to MIME in a StringBuilder
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeSb method, which renders an Email object as MIME text and appends the result to a StringBuilder, without sending the email. This example renders a message into a StringBuilder and prints it.
Background: This is the
StringBuilder version of RenderToMime. Appending into a StringBuilder is more efficient when the MIME is large or when you plan to further inspect or manipulate it — searching, replacing, or accumulating additional text — without creating extra intermediate string copies.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,
Chilkat.StringBuilder,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
email: TEmail;
sbMime: TStringBuilder;
begin
success := False;
// Demonstrates the MailMan.RenderToMimeSb method, which renders an Email object as MIME text
// and appends the result to a StringBuilder (without sending the email).
mailman := TMailMan.Create;
// Build the email to render.
email := TEmail.Create;
email.Subject := 'Rendered email';
email.From := 'alice@example.com';
email.AddTo('Bob','bob@example.com');
email.Body := 'This message is rendered to MIME in a StringBuilder.';
// Render the MIME into a StringBuilder.
sbMime := TStringBuilder.Create;
success := mailman.RenderToMimeSb(email,sbMime);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
WriteLn(sbMime.GetAsString());
mailman.Free;
email.Free;
sbMime.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.