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

烈酒焚心 提交于 2019-12-14 02:26:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!