2011-07-16 42 views
0

我处于整个电子邮件及其部分以正确顺序生成并嵌套的位置......除了一件小事。 :part_container参数在文本/ html部分的上方插入内联附件,而不是在下面。如果在上面,Thunderbird将不会显示任何内容,并会显示电子邮件为2个外部附件。如果我手动编辑电子邮件并将text/html部分下方的内联部分移动,它会完美显示。Rails 2.3“inline_attachment”gem内联附件的位置不正确

part :content_type => 'multipart/alternative' do |copy| 
    copy.part :content_type => 'text/plain' do |plain| 
     plain.body = render(
      :file => "main.text.plain", 
      :body => { 
        :user => @user, 
        :text => docParse.to_plain_text 
        } 
      ) 
    end 
    copy.part :content_type => 'multipart/related' do |rel| 
     rel.part :content_type => 'text/html' do |html| 
      html.body = render(
       :file => "main.text.html", 
       :body => { 
         :part_container => rel, 
         :user => @user, 
         :content => content, 
         :email_links => m.email_links, 
         :nav_image => m.nav_image 
         } 
       ) 
     end 
    end 
end 
m.attachments.each do |file| 
    attachment :content_type => "application/octet-stream", 
       :filename  => File.basename(file), 
       :body   => File.read(file) 
end 

要明确的是,inline_attachments宝石完美的作品没有任何这段代码的 - 但只有当我发送邮件,无需任何外部附件(只内嵌图片)。当我想发送带有内嵌图像和外部附件的HTML电子邮件时,这是我必须诉诸的。

编辑:要清楚,我的问题是:“我如何确保该内嵌附件部分text/html的一部分使用后产生的?part_container

+0

没人?该死... – JakeTheSnake

回答

1

配件包含部分阵列...

rel.parts.unshift rel.parts.pop 

实质上,电子邮件是由'部分'组成的......这些部分属于一个部分数组,每个部分都可以有自己的部分数组(嵌套部分),看看'part_container' inline_attachments'gem以错误的顺序创建零件(文本/ html部分LAST而不是FIRST),我通过弹出最后一个零件项目来重新排序相关零件数组 - 这正好是text/html的部分(rel.parts.pop)并将其插入作为相对部分阵列中的第一项(rel.parts.unshift)


直列图像部分
直列图像部分
直列图像部分
text/html的部分

成为

text/html的部分
直列图像部分
直列图像 - 对艺术
嵌入图像部分

并且一切正常显示。

这是参考脚本我的问题最新的脚本:

part :content_type => 'multipart/alternative' do |copy| 
    copy.part :content_type => 'text/plain' do |plain| 
     plain.body = render(
      :file => "main.text.plain", 
      :body => { 
        :user => @user, 
        :text => docParse.to_plain_text 
        } 
      ) 
    end 
    copy.part :content_type => 'multipart/related' do |rel| 
     rel.part :content_type => 'text/html' do |html| 
      html.body = render(
       :file => "main.text.html", 
       :body => { 
         :part_container => rel, 
         :user => @user, 
         :content => content, 
         :email_links => m.email_links, 
         :nav_image => m.nav_image 
         } 
       ) 
     end 
     # Place the text/html part before all other inline images 
     rel.parts.unshift rel.parts.pop 
    end 
end 
m.attachments.each do |file| 
    attachment :content_type => "application/octet-stream", 
       :filename  => File.basename(file), 
       :body   => File.read(file) 
end 
+0

这是一个答案,评论,或..? –

+0

它被列为答案。我打算将它标记为已回答,但我必须等待2天。 – JakeTheSnake

+0

我只是问,因为我不清楚这是如何回答你的问题。当然,对于你来说很明显,但即使你自己回答你的问题,也可以让其他人从你的发现中受益,即更详细:) –