如何集成“预邮件程序”带导轨

发布于 2024-11-09 13:02:51 字数 365 浏览 2 评论 0原文

如何将“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

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

How does one integrate the 'premailer' gem with a Rails (3.0.7) project? I currently have in my mailer:

def welcome(user)
  @user = user

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

But I can't figure out how to integrate the library. I need to call:

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

However, I'm not sure how to access the contents of my email from a mailer action.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一向肩并 2024-11-16 13:02:51

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

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

我最亲爱的 2024-11-16 13:02:51

尝试:

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

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
羁绊已千年 2024-11-16 13:02:51

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

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

这就是我所要做的。希望这有帮助!

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!

旧故 2024-11-16 13:02:51

或者

gem "actionmailer_inline_css"

or

gem "actionmailer_inline_css"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文