我正在使用mailgun(尽管这个问题与mailgun无关)来解析传入的电子邮件,并且mailgun会将解析后的电子邮件http发布到我的服务器。
当我收到帖子时,我得到了多部分电子邮件的 html 代码。
我想向我的用户显示 html 电子邮件,我使用的是 Rails,所以它就像
<div>
<%= raw(message.body_html) %>
</div>
但是,它看起来与我在 yahoo 或 hotmail 中查看同一封电子邮件时不同(我知道不同的电子邮件客户端会以不同的方式显示 html 电子邮件,但我的看起来截然不同)。
Here is how it looks on my self-built client:
And this is how it looks in yahoo for the same email:
我使用 Zurb Foundation 作为我的造型框架。然而,我认为电子邮件 html 带有自己的内联样式,我查看了它看起来确实像的代码,然后它看起来应该与其他客户端足够相似。
那么,假设您获得一段 html 代码并希望按原样显示它而不让其他框架覆盖其样式,那么显示 html 电子邮件的最佳实践是什么?
此外,是否可以禁用代码块的 Foundation(或 twitter bootstrap)样式,例如,类似
<div>
<% disable_foundation_styling begin %>
<%= raw(message.body_html) %>
<% end %>
</div>
当然“disable_foundation_styling”只是我的想象。
提前致谢!
!!!!!!!!!更新 1/1/2013 !!!!!!!!!!!!!!!
As @Alex L. suggested, I tried but it doesn't quiet work as expected.
The iframe renders everything in the view as before (see picture below), and that's understandable, since the iframe content is just the view of another controller, which in the case rails will include all the application layout templates as well. However, the toolbar is not my biggest concern, it's what's inside the iframe just looks exactly as before.
我怀疑 iframe 可能不是这样做的方法。我查看了gmail和yahoo的代码,他们都不使用iframe。相反,他们使用非常深的嵌套来呈现 html 电子邮件。 html 电子邮件的部分对于 yahoo 和 gmail 具有相同的代码,只是 yahoo 为每个 DOM 元素插入自己的 id。
所以现在我怀疑有一些基础样式影响了它的外观。
一旦我了解更多信息,我会更新。