Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Access Attached Message (Embedded Email)
How to access an email embedded within another email (i.e. an attached message).Chilkat Pascal (Lazarus/Delphi) Downloads
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;
numAttached: Integer;
email2: TEmail;
begin
success := False;
email := TEmail.Create;
// Load an email from a .eml
success := email.LoadEml('embeddedEmail.eml');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// Display how many attached emails are embedded within
// this one:
numAttached := email.NumAttachedMessages;
WriteLn('numAttached = ' + numAttached);
// Get the 1st attached message.
email2 := TEmail.Create;
success := email.GetAttachedEmail(0,email2);
if (success = True) then
begin
// Display the subject, From, and a header field...
WriteLn(email2.Subject);
WriteLn(email2.From);
WriteLn(email2.GetHeaderField('X-SOMETHING'));
end;
email.Free;
email2.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.