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

Get Delivery-Status Info as JSON

See more Email Object Examples

Demonstrates the Chilkat Email.GetDsnInfo method, which — when IsMultipartReport indicates the email is a multipart/report — obtains the delivery-status information as a JsonObject. This example loads a bounce message, confirms it is a report, and prints the extracted DSN details as JSON.

Background: A bounce (DSN) carries its key facts — which recipient failed, the status code, the reporting server — in a machine-readable message/delivery-status part. Rather than parsing those raw fields yourself, GetDsnInfo gathers them into a structured JSON document you can query with the JsonObject API, making it easy to automate bounce handling and prune failed addresses from a mailing list.

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,
  Chilkat.JsonObject;

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

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;
  json: TJsonObject;

begin
  success := False;

  //  Demonstrates the GetDsnInfo method, which, for a multipart/report email, obtains the
  //  delivery-status information as a JSON object.

  email := TEmail.Create;

  success := email.LoadEml('qa_data/eml/dsn_bounce.eml');
  if (success = False) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  //  Only meaningful for a multipart/report email.
  if (email.IsMultipartReport() = True) then
    begin
      json := TJsonObject.Create;
      success := email.GetDsnInfo(json);
      if (success = True) then
        begin
          WriteLn(json.Emit());
        end;
    end
  else
    begin
      WriteLn('This email is not a multipart/report.');
    end;

  //  Note: The path "qa_data/..." is a relative local filesystem path,
  //  relative to the current working directory of the running application.


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