Ruby Requires Chilkat v11.0.0+
Ruby
Create an HTML preview with embedded images
See more Email Object Examples
Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.
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
preview = Chilkat::CkEmail.new()
success = email.MakeCopy(preview)
if (success != true)
print email.lastErrorText() + "\n";
exit
end
# Keep related items: the HTML still refers to them.
preview.DropAttachments()
print "Files in original: " + email.get_NumAttachments().to_s() + " Files in preview: " + preview.get_NumAttachments().to_s() + "\n";
if (preview.HasHtmlBody() != true)
print "This message has no HTML preview." + "\n";
exit
end
html = Chilkat::CkStringBuilder.new()
success = preview.GetHtmlBodySb(true,html)
if (success != true)
print preview.lastErrorText() + "\n";
exit
end
success = html.WriteFile("preview.html","utf-8",false)
if (success != true)
print "Failed: html.WriteFile." + "\n";
exit
end
print "Saved preview.html." + "\n";