将外部CSS转换为内联CSS的邮件在Rails [英] Converting External CSS to Inline CSS for Mail in Rails

查看:232
本文介绍了将外部CSS转换为内联CSS的邮件在Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序,该应用程序将发送样式很重的电子邮件,并要求客户端在Google的Gmail之外工作。我研究了这个问题,它看起来像Gmail从外部文件或CSS嵌套在样式标签中删除CSS。

I am trying to create an application that will send out style-heavy emails and have required clients working except Google's Gmail. I researched the issue and it looks like Gmail strips out CSS from external files or CSS nested in the 'style' tag. Does an easy way exist of moving style from an external file to being inline?

需要一些简单的方法:

<style>
.wide { width: 100px; }
.cell { display: block; }
</style>
<span class="wide cell">Sample</span>

并将其转换为:

<div class="wide cell" style="width: 100px; display: block;">Sample</div>


$ b

谢谢!

Thanks!

推荐答案

添加了 premailer

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 ...
end

这篇关于将外部CSS转换为内联CSS的邮件在Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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