问题
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?
回答1:
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}
来源:https://stackoverflow.com/questions/3997725/how-to-attach-xls-files-to-email-when-sending-from-rails-and-not-getting-the-at