From: grooveska Date: 2007-06-02T03:30:25+09:00 Subject: Help with emailing attachments with Ruby... I am working on a script that will send an email with a .csv file attachment. I can get everything set correctly, and the email gets sent properly. The problem is with the attachments. This maybe a MIME thing instead of something wrong with my script. My script is based on an example from Hal Fulton's The Ruby Way book. If anyone has any suggestions or see something I did wrong I would greatly appreciate it. Below is my script. Below that is what the email I receive looks like. Thanks! ***Begin Script*** require 'time' require 'net/smtp' require 'date' ################################################################## # This portion of the code assembles the filenames of the files # # to be attached in the email # ################################################################## time = Time.now #set time object to the current time month = time.month #grab the number of the month from the current time day = time.day #grab the day of the current time year = time.year #grab the year of the current time month = month + 1 #to match the format of Ian's file names if month < 10 #formatting fullmonth = "0" + month.to_s else fullmonth = month.to_s end if day < 10 fullday = "0" + day.to_s else fullday = day.to_s end #end of formatting filename1 = "pagecount-" + year.to_s + fullmonth + fullday + ".csv" #assemble file name ##################################### # Attach files and send the email # #################################### def text_plus_attachment (subject, body, filename) marker = "MIME_boundary" middle = "--#{marker}\n" ending = "--#{middle}--\n" content = "Content-Type: Multipart/Related; " + "boundary=#{marker}; " + "typw=text/plain" head1 = <<-EOF MIME-Version: 1.0 #{content} Subject: #{subject} EOF binary = File.read(filename) encoded = [binary].pack("m") # base64 econding head2 = <<-EOF Content-Description: "#{filename}" Content-Type: text/plain; name="#{filename}" Content-Transfer-Encoding: Binary Content-Disposition: attachment; filename="#{filename}" EOF #Return head1 + middle + body + middle + head2 + encoded + ending end body = <