Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get an Email's MIME into a BinData
See more Email Object Examples
Demonstrates the Chilkat Email.GetMimeBd method, which serializes the complete RFC822/MIME message (headers, body representations, related items, and attachments) and appends the bytes to a BinData object. This example builds a message, serializes it to a BinData, and prints the byte count.
Background: A
BinData holds raw bytes, which is the right container when you want the MIME as binary rather than text — for example to write it directly to a file or socket, hash it, or hand it to another API that expects a byte buffer. It is the binary counterpart to GetMime (string) and GetMimeSb (StringBuilder).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.Email,
Chilkat.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
bdMime: TBinData;
begin
success := False;
// Demonstrates the GetMimeBd method, which serializes the complete RFC822/MIME message
// (headers, bodies, related items, and attachments) and appends the bytes to a BinData
// object.
email := TEmail.Create;
email.Subject := 'GetMimeBd example';
email.From := 'alice@example.com';
email.AddTo('Bob','bob@example.com');
email.Body := 'Hello!';
// Append the complete MIME to a BinData object.
bdMime := TBinData.Create;
success := email.GetMimeBd(bdMime);
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('MIME size (bytes) = ' + bdMime.NumBytes);
email.Free;
bdMime.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.