Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
email: TChilkatEmail;
i: Integer;
referenceId: WideString;
reader: THtmlToText;
begin
success := 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TChilkatEmail.Create(Self);
success := email.LoadEml('with-attachments.eml');
if (success <> 1) then
begin
Memo1.Lines.Add(email.LastErrorText);
Exit;
end;
Memo1.Lines.Add('From: ' + email.From);
Memo1.Lines.Add('Subject: ' + email.Subject);
Memo1.Lines.Add('Date: ' + email.EmailDateStr);
i := 0;
while (i < email.NumTo) do
begin
Memo1.Lines.Add('To: ' + email.GetToName(i) + ' ' + email.GetToAddr(i));
i := i + 1;
end;
referenceId := email.GetHeaderField('X-Reference-ID');
if (email.LastMethodSuccess = 1) then
begin
Memo1.Lines.Add('Reference: ' + referenceId);
end;
if (email.HasPlainTextBody() = 1) then
begin
Memo1.Lines.Add(email.GetPlainTextBody());
end
else
begin
if (email.HasHtmlBody() = 1) then
begin
reader := THtmlToText.Create(Self);
Memo1.Lines.Add(reader.ToText(email.GetHtmlBody()));
end
else
begin
Memo1.Lines.Add('No text or HTML body.');
end;
end;