Search code examples
ruby-on-rails-3mimeexport-to-excelactionmailer

How to attach xls files to email when sending from rails, and not getting the attachment corrupt?


If I attach xls files as attachment in the mailer like this

attachments["1.xls"] = File.read "1.xls"

If I try open the attachment from the received mail, Excel is unable to open and it says the file is corrupted.

Please let me know if I am missing something? Please let me know if additional information is needed?


Solution

  • Found the answer here http://www.dixis.com/?paged=3

    Apparently The correct way to attach binary files on Windows is

    attachments[file_name] = File.open(file_location, 'rb'){|f| f.read}