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

Create an Inline-Forward Email

See more Email Object Examples

Demonstrates the Chilkat Email.ToForward method, which creates an inline-forward email based on this email. The forward is returned in the argument, and the source email is not modified. The returned email can be edited — adding recipients, prepending a note — before sending. This example forwards a message and adds a recipient.

Background: An inline forward quotes the original message's content within the body of the new message — the familiar "---------- Forwarded message ----------" style — as opposed to attaching the original as a message/rfc822 part (which AttachEmail does). Chilkat assembles the quoted body and headers for you, leaving the new message ready to address and send.

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.Email;

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

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;
  fwd: TEmail;

begin
  success := False;

  //  Demonstrates the ToForward method, which creates an inline-forward email based on this
  //  email.  The forward is returned in the argument; the source email is not modified.

  email := TEmail.Create;
  email.Subject := 'Quarterly results';
  email.From := 'alice@example.com';
  email.AddTo('Bob','bob@example.com');
  email.Body := 'Here are the quarterly results.';

  //  Create an inline-forward email from this message.
  fwd := TEmail.Create;

  success := email.ToForward(fwd);
  if (success = False) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  //  The forward can be edited to add recipients before sending.
  fwd.AddTo('Carol','carol@example.com');

  WriteLn(fwd.GetMime());


  email.Free;
  fwd.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.