Sample code for 30+ languages & platforms
Delphi DLL

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Mime, StringTable;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
mime: HCkMime;
st: HCkStringTable;
n: Integer;
i: Integer;

begin
success := False;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

mime := CkMime_Create();

// Load a MIME document from a file:
// (.mht and .eml files contain MIME).
success := CkMime_LoadMimeFile(mime,'mst.mht');
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

st := CkStringTable_Create();
success := CkMime_PartsToFiles(mime,'/temp/mimeParts',st);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

n := CkStringTable_getCount(st);

// Display the paths of the files created:
i := 0;
while i < n do
  begin
    Memo1.Lines.Add(CkStringTable__stringAt(st,i));
    i := i + 1;
  end;

CkMime_Dispose(mime);
CkStringTable_Dispose(st);

end;