From: gregarican Date: 2009-01-17T00:33:55+09:00 Subject: Re: Programmatically adding an Excel attachment On Jan 15, 4:23 pm, gregarican wrote: > I've checked out this page -->http://www.tutorialspoint.com/ruby/ruby_sending_email.htm > that shows how to e-mail a text file attachment.I'm trying to attach > an Excel file, but the receiver gets a corrupted file attachment. I've > changed the Content-Type: in the MIME header to application/vnd.ms- > excel but it doesn't seem to work. Anyone care to offer a quick code > snippet that will fit the bill? I solved my own problem. It was just a question of me not parsing the Excel file correctly. Since I was basing things off sample code that opened plain text files to send as attachments, I wasn't building the attachment properly. Here's a snipped of my little routine. Works like a champ, and I didn't have to install ActionMailer or any other module since I cobbled the code together manually. It will fit the bill! Code is below if anyone runs into a similar quandary. ----------------------------------- # Read a file and encode it into base64 format savedDoc = path+filename file = File.open(savedDoc, 'rb') filecontent = file.read() encodedcontent = [filecontent].pack("m*") # base64 marker = "AUNIQUEMARKER" body =< To: You Subject: Message with Excel Attachment MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=#{marker} --#{marker} EOF # Define the message action part2 =< e print "Exception occured: " + e end