Sending a Zip File as attachment

require ‘digest/sha1’
require ‘net/smtp’
toEmail =
toEmail << “1NAME <[email protected]>”
fromEmail = “[email protected]
fromEmailAlias = “CyberDevDrona”
part1 =<<EOF
Subject: Expert review for kata in language.
MIME-Version: 1.0
attachment :content_type => “application/zip”,
:body =>,
:filename => File.basename(tfile_name)
Content-Type:“application/zip”; boundary=#{marker}

part2 =<<EOF

part3 =<<EOF
Content-Type: zip/attachment; name="#{tfile_name}"
Content-Disposition: attachment; filename="#{tfile_name}"

mailtext = part1 + part2 + part3

  Net::SMTP.start('localhost') do |smtp|
                    smtp.send_message mailtext, fromEmail, toEmail

I used this code to send my zip file as attachment but iam getting empty
zip file in mail. Could you please suggest me how to send a zip file as
attachment in ruby.

I didn’t check your code but I think I same problem and want share solution:

:body => File.binread(tfile_name)

If you get file using “read” you catch only frame, binread take all, include inside file

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs