Ruby发送带有/usr/sbin/sendmail附件的电子邮件 [英] Ruby send email with an attachment with /usr/sbin/sendmail
问题描述
我正在尝试发送带有csv文件的电子邮件进行附件. 我会执行以下操作,但是我只会收到一封电子邮件,其中包含一个空的csv文件(而不包含其内容).你能帮我吗? 我不想使用任何额外的库,所以请不要告诉我使用pony左右;-)
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="me@exemple.com"
subject='The subject'
from='"Name" <you@exemple.com>'
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]
谢谢
推荐答案
/usr/sbin/sendmail
对附件一无所知,并根据 RFC 2045 将消息格式化为MIME消息.有关此类消息的示例,请参见 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.
这篇关于Ruby发送带有/usr/sbin/sendmail附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!