Ruby 使用 /usr/sbin/sendmail 发送带有附件的电子邮件
我正在尝试发送一封带有 csv 文件作为附件的电子邮件。 我执行以下操作,但只收到一封包含空 csv 文件(而不包含其内容)的电子邮件。你能帮我一下吗? 我不想使用任何额外的库,所以请不要告诉我使用 pony 等;-)
to="[email protected]"
subject='The subject'
from='"Name" <[email protected]>'
description ="Desc"
csvnamefile = "/path/to/file/filename.csv"
puts value = %x[/usr/sbin/sendmail #{to} << EOF
subject: #{subject}
from: #{from}
Content-Description: "#{csvnamefile}"
Content-Type: multipart/mixed; name="#{csvnamefile}"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename="#{csvnamefile}"
Description : #{description}
EOF]
谢谢
I am trying to send an email with a csv file for attachement.
I do the following but I only receive an email with a empty csv file (and not with the content of it). Can you please help me on that?
I don't want to use any extra library so please don't tell me to use pony or so ;-)
to="[email protected]"
subject='The subject'
from='"Name" <[email protected]>'
description ="Desc"
csvnamefile = "/path/to/file/filename.csv"
puts value = %x[/usr/sbin/sendmail #{to} << EOF
subject: #{subject}
from: #{from}
Content-Description: "#{csvnamefile}"
Content-Type: multipart/mixed; name="#{csvnamefile}"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename="#{csvnamefile}"
Description : #{description}
EOF]
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢亚历克斯。我可以让它与你的信息一起工作。
最终的工作结果如下所示:
Thanks Alex. I could make it work with your informations.
The final working result looks like this:
/usr/sbin/sendmail
对附件一无所知,并根据 RFC 5322 作为平面 US-ASCII 文本。要将文件作为附件发送,您需要根据 RFC 2045。有关此类消息的示例,请参阅RFC 2049 的附录 A。/usr/sbin/sendmail
doesn't know anything about attachments and treats email message body according to RFC 5322 as flat US-ASCII text. To send a file as attachment you need to format your message as MIME message according to RFC 2045. For example of such a message see Appendix A to RFC 2049.