2

在 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

与其他邮件一起使用 Outlook、Exchange 等是非常有气质的。

我如何在 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 是我需要编写的一个进行 7 位编码的类吗?

谢谢乔尔

4

1 回答 1

0

所以事实证明 rails 3 actionmailer 非常聪明,这似乎工作正常:

@mailbody = body
attachments["icann.eml"] = {:content => email.raw_email }
mail(:to => to, :from => from, :subject => subject) 
于 2012-11-23T15:59:11.563 回答