Ruby Requires Chilkat v11.0.0+
Ruby
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 Ruby Downloads
require 'chilkat'
success = false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = Chilkat::CkEmail.new()
success = email.LoadEml("with-attachments.eml")
if (success != true)
print email.lastErrorText() + "\n";
exit
end
print "From: " + email.ck_from() + "\n";
print "Subject: " + email.subject() + "\n";
print "Date: " + email.emailDateStr() + "\n";
i = 0
while (i < email.get_NumTo())
print "To: " + email.getToName(i) + " " + email.getToAddr(i) + "\n";
i = i + 1
end
referenceId = email.getHeaderField("X-Reference-ID")
if (email.get_LastMethodSuccess() == true)
print "Reference: " + referenceId + "\n";
end
if (email.HasPlainTextBody() == true)
print email.getPlainTextBody() + "\n";
else
if (email.HasHtmlBody() == true)
reader = Chilkat::CkHtmlToText.new()
print reader.toText(email.getHtmlBody()) + "\n";
else
print "No text or HTML body." + "\n";
end
end