10

如何将“ premailer ”gem 与 Rails (3.0.7) 项目集成?我目前在我的邮件中:

def welcome(user)
  @user = user

  mail to: user.email, subject: "Welcome"
end

但我不知道如何整合图书馆。我需要打电话:

premailer = Premailer.new(html)
html = premailer.to_inline_css

但是,我不确定如何通过邮件操作访问我的电子邮件内容。

4

4 回答 4

11

看看我最近写的简单的premailer-rails gem 。它使用 Rails 邮件程序挂钩进行转换。

于 2011-05-31T17:14:27.613 回答
5

尝试:

def premailer(message)
  message.text_part.body = Premailer.new(message.text_part.body.to_s, with_html_string: true).to_plain_text
  message.html_part.body = Premailer.new(message.html_part.body.to_s, with_html_string: true).to_inline_css

  return message
end

def welcome(user)
  @user = user

  message = mail to: user.email, subject: "Welcome"
end
于 2011-05-27T02:17:05.003 回答
5

对于 Rails 4 用户,您可以: 添加 gem

gem 'premailer-rails'
gem 'nokogiri' (if you don't have it)

将此添加到您的样式表(Haml):

%style{type:"text/css"}= Rails.application.assets.find_asset('email_stylesheet').to_s

由于某种原因,它不能使用普通的 stylesheet_link_tag

这就是我必须做的。希望这有帮助!

于 2014-08-15T23:28:47.417 回答
1

或者

gem "actionmailer_inline_css"
于 2012-11-28T14:09:33.770 回答