Ruby Requires Chilkat v11.0.0+
Ruby
Read the plain-text and HTML bodies separately
See more Email Object Examples
When both alternatives exist, Body returns HTML. Use the explicit body accessors to choose text for an index or HTML for a viewer. This example reads alternatives.eml from the previous example.
Chilkat Ruby Downloads
require 'chilkat'
success = false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = Chilkat::CkEmail.new()
success = email.LoadEml("alternatives.eml")
if (success != true)
print email.lastErrorText() + "\n";
exit
end
# A message can have either representation, both, or neither.
if (email.HasPlainTextBody() == true)
print "Plain text: " + email.getPlainTextBody() + "\n";
end
if (email.HasHtmlBody() == true)
print "HTML source: " + email.getHtmlBody() + "\n";
end
if ((email.HasPlainTextBody() == false) and (email.HasHtmlBody() == false))
print "No text or HTML body. Inspect the MIME parts." + "\n";
end