在rails 2.3.5中,我们可以使用以下代码将电子邮件附加到其他电子邮件的附件中,这些电子邮件是多部分电子邮件:
recipients to
from from
subject subject
content_type "multipart/mixed"
part "text/html" do |p|
p.body = render_message("rampup_notification.text.html.erb", :mailbody => body)
end
part "text/plain" do |p|
p.body = render_message("rampup_notification.text.plain.erb", :mailbody => body)
end
email = enrollment_application.email
if email != nil && email.raw_email != nil
attachment :content_type => "message/rfc822", :filename => "icann.eml", :body => email.raw_email, :transfer_encoding => '7bit'
end
与其他邮寄者一起开展前景,交流等工作非常有气质。
我如何在rails 3中执行此操作?
我明白了:http://www.rubydoc.info/docs/rails/3.0.0/ActionMailer/Base:attachments
encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
:encoding => 'SpecialEncoding',
:content => encoded_content }
但是我不明白如何使用它,SpecialEncode是一个我需要写的那个做7bit编码的类吗?
感谢 乔尔
答案 0 :(得分:0)
所以事实证明rails 3 actionmailer非常聪明,这似乎工作正常:
@mailbody = body
attachments["icann.eml"] = {:content => email.raw_email }
mail(:to => to, :from => from, :subject => subject)