我正在尝试使用带有Ruby 1.9.3的gem’mail’发送电子邮件.它包含text / html和text / plain部分,它们应作为替代部件和附件嵌入.
这是我目前的代码:
require 'mail'
mail = Mail.new
mail.delivery_method :sendmail
mail.sender = "me@example.com"
mail.to = "someguy@example.com"
mail.subject = "Multipart Test"
mail.content_type = "multipart/mixed"
html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body "
HTML
"end
text_part = Mail::Part.new do
body "TEXT"
end
mail.part :content_type => "multipart/alternative" do |p|
p.html_part = html_part
p.text_part = text_part
end
mail.add_file :filename => "file.txt", :content => "FILE"
mail.deliver!
它会导致邮件中有替代零件,但没有附件.我正在使用thunderbird 10.0.12进行测试.
有人能够让这个例子有效吗?
谢谢,
krissi