Rails-使用邮件程序模板为多部分电子邮件设置多个布局 [英] Rails - setting multiple layouts for a multipart email with mailer templates

查看:106
本文介绍了Rails-使用邮件程序模板为多部分电子邮件设置多个布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,Rails 2.2添加了邮件发件人布局,这很不错,只是我在发送多部分电子邮件时不知道如何使它们工作。.它用相同的布局将邮件内容包装为两个文本/ plain版本和text / html版本。我想要的是将布局仅包装在文本/ html版本周围,或者为每个版本单独包装。

So Rails 2.2 added mailer layouts, which is great, except that I can't figure out how to make them work when I'm sending a multipart email..it's wrapping my mail content with the same layout for both the text/plain version and the text/html version. What I want is to wrap my layout around either only the text/html version, or to be able to have a separate layout for each.

有人遇到过吗?我没有在其他地方看到它,

Anybody encountered this? I haven't seen any mention of it elsewhere,

Cameron

推荐答案

<为了供以后参考,下面将上述博客文章中的解决方案(在第二篇博客文章中进行了修改)全部归功于上述博客文章。 解决方案博客文章

将此代码添加到您的environment.rb文件中,以阻止邮件程序将布局应用于纯文本电子邮件。它还具有检查功能,可以阻止它与异常通知插件冲突。

Add this code to your environment.rb file to stop the mailer from applying layouts to plain text emails. It also has a check that will stop it from conflicting with the exception notification plugin.

# Do not use the mailer layout template for plain text emails
module ActionMailer
  class Base
    private    
    def candidate_for_layout?(options)
       (!options[:file] || !options[:file].respond_to?(:content_type) ||
          options[:file].content_type != 'text/plain') &&
          !@template.send(:_exempt_from_layout?, default_template_name)
    end
  end
end

这篇关于Rails-使用邮件程序模板为多部分电子邮件设置多个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆