C# Requires Chilkat v11.0.0+
C#
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 C# Downloads
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Chilkat.Email email = new Chilkat.Email();
success = email.LoadEml("with-attachments.eml");
if (success != true) {
Debug.WriteLine(email.LastErrorText);
return;
}
Debug.WriteLine("From: " + email.From);
Debug.WriteLine("Subject: " + email.Subject);
Debug.WriteLine("Date: " + email.EmailDateStr);
int i = 0;
while ((i < email.NumTo)) {
Debug.WriteLine("To: " + email.GetToName(i) + " " + email.GetToAddr(i));
i = i + 1;
}
string referenceId = email.GetHeaderField("X-Reference-ID");
if (email.LastMethodSuccess == true) {
Debug.WriteLine("Reference: " + referenceId);
}
if (email.HasPlainTextBody() == true) {
Debug.WriteLine(email.GetPlainTextBody());
}
else {
if (email.HasHtmlBody() == true) {
Chilkat.HtmlToText reader = new Chilkat.HtmlToText();
Debug.WriteLine(reader.ToText(email.GetHtmlBody()));
}
else {
Debug.WriteLine("No text or HTML body.");
}
}