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

Create a Reply Email

See more Email Object Examples

Demonstrates the Chilkat Email.ToReply method, which generates a reply email with updated header and body fields so it can be sent as a reply. Attachments are excluded from the reply, but attached messages are included. The source email is not modified. This example creates a reply and prints its MIME.

Background: Replying is more than swapping sender and recipient: the To is set from the original's reply address, the subject gets an Re: prefix, the original text is quoted, and threading headers (In-Reply-To, References) are added so mail clients group the conversation. ToReply assembles all of that, leaving a message you can edit and send. Dropping attachments is the usual reply convention — you rarely echo the sender's files back to them.

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;
  reply: TEmail;

begin
  success := False;

  //  Demonstrates the ToReply method, which generates a reply email with updated header and
  //  body fields ready to send as a reply.  Attachments are excluded from the reply, but
  //  attached messages are included.  The source email is not modified.

  email := TEmail.Create;
  email.Subject := 'Project update';
  email.From := 'alice@example.com';
  email.AddTo('Bob','bob@example.com');
  email.Body := 'Here is the project update.';

  //  Create a reply email based on this message.
  reply := TEmail.Create;

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

  //  The reply is addressed and quoted, ready to edit and send.
  WriteLn(reply.GetMime());


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