How to Integrate 'premailer' with Rails

两盒软妹~` 提交于 2019-11-30 12:54:39

Try:

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
fphilipe

Have a look at the simple premailer-rails gem I recently wrote. It uses Rails mailer hooks to do the conversion.

For Rails 4 users you can: add the gems

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

add this to your stylesheet (Haml):

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

for some reason it wasn't working with a normal stylesheet_link_tag

That's all I had to do. Hope this help!

or

gem "actionmailer_inline_css"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!