Sample code for 30+ languages & platforms
Ruby Requires Chilkat v11.0.0+

Set a MIME header on one attachment

See more Email Object Examples

Add a file using the content type required by the receiving application. Set Content-Description on the newly added MIME part and read it back from that part. The message-level headers have a separate collection.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

success = false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

email = Chilkat::CkEmail.new()
email.put_From("Workshop team <events@example.com>")
success = email.AddTo("Alex Rivera","alex@example.net")
if (success != true)
    print email.lastErrorText() + "\n";
    exit
end

email.put_Subject("Workshop registration")
email.put_Body("Attached is the requested data file.")
success = email.AddFileAttachment2("sample.hpm","application/x-hprimnet")
if (success != true)
    print email.lastErrorText() + "\n";
    exit
end

index = email.get_NumAttachments() - 1
email.AddAttachmentHeader(index,"Content-Description","HPM/3.0")
print email.getAttachmentHeader(index,"Content-Description") + "\n";

success = email.SaveEml("described-attachment.eml")
if (success != true)
    print email.lastErrorText() + "\n";
    exit
end

print "Saved described-attachment.eml." + "\n";