【问题标题】:Rails mailer stylingRails 邮件样式
【发布时间】:2023-04-03 13:43:02
【问题描述】:

为什么我会在我的邮件中收到默认样式的邮件?在代码中我对其进行了一些样式设置,但为什么在 gmail 上我看到默认布局? 我的代码是这样的:

!!!
%html
  %head
    %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
      %title Покупка автозапчастей
      :css
        body, td { background-color:#cecece; color:#000000; font-size:14px; font-family:Verdana,Helvetica,Arial; }
        .blue { background-color: blue; height:2px; color: white; }
        .notice {margin: 10px auto;  background-color: #fbb752;  border: 1px solid #cecece; }
  %body
    .blue
      %h3
        Новый заказ
      %b
        Внимание, недавно на сайте сформирован новый заказ!
        = @order.id
    .notice
      %table
        %tr
          %th
            id клиента
          %th
            Улица
          %th
            Здание
          %th
            Общая сумма
          %th
            Статус
          %th
            Открыт
        %tr
          %td
            = @order.user.id
            = @order.user.email
          %td
            %b
              = @order.street
          %td
            = @order.building
          %td
            %b
              = @order.totalcost
          %td
            %b
              = @order.orderstatus.name
          %td
            = @order.created_at
      %br/
      %table
        %tr
          %th
            Артикул
          %th
            Цена
          %th
            Количество      
        - @order.line_items.each do |l|
          %tr{ :class => cycle("zebra-stripe zebra-grey zebra1", "zebra-stripe zebra-grey zebra2")}      
            %td
              = l.description
            %td
              = l.price
            %td
              = l.quantity

那么,如何让我的邮件发送者在我的电子邮件服务 (gmail) 上像我的代码一样发送良好样式的信件?

【问题讨论】:

    标签: css ruby-on-rails haml sass actionmailer


    【解决方案1】:

    Gmail 会从 HTML 电子邮件中删除所有 <style> 标记。

    如果您希望自己的样式出现在 Gmail 中,则需要使用内联样式属性。

    【讨论】:

    • 请注意,有一些工具可以自动将 css 转换为内联样式。使用谷歌。
    • 在其他服务上我也没有看到我的布局!问题出在代码中
    • @brabertaser1992:那是因为他们确实使用了style="" 属性。
    • 哼哼,为什么比这里更有效? railscasts.com/episodes/312-sending-html-email?view=asciicast
    • @brabertaser1992:您需要使用 style="" 属性将它们直接应用到每个元素,而不是使用 CSS 选择器来应用属性。
    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多