Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Set a MIME Body from Plain Text

See more MIME Examples

Demonstrates the Chilkat Mime.SetBodyFromPlainText method, which sets the body as plain text. The only argument is the text. For ASCII input Chilkat uses text/plain with 7bit encoding; for non-ASCII it selects an appropriate charset and encoding.

Background: This is the simplest way to give a MIME entity a text body — Chilkat picks a sensible Content-Type and transfer encoding for you based on the content. Plain ASCII stays as 7bit with no charset, while text containing accented or non-Latin characters gets a charset (typically UTF-8) and a suitable encoding so it survives transmission intact. It is the text counterpart to SetBodyFromHtml and SetBodyFromXml.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  mime: TMime;
  mimeText: string;

begin
  success := False;

  //  Demonstrates the Mime.SetBodyFromPlainText method, which sets the body as plain text.  The only
  //  argument is the text.  For ASCII, Chilkat sets Content-Type: text/plain and a 7bit transfer
  //  encoding; for non-ASCII it selects an appropriate charset and encoding.

  mime := TMime.Create;

  success := mime.SetBodyFromPlainText('Hello, this is a plain-text message body.');
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  mimeText := mime.GetMime();
  if (mime.LastMethodSuccess = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;
  WriteLn(mimeText);


  mime.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.