Html 如何在ruby中设计自动邮件格式

Html 如何在ruby中设计自动邮件格式,html,css,ruby-on-rails,ruby,email,Html,Css,Ruby On Rails,Ruby,Email,我想通过SMTP发送自动邮件- daily\u closing.html.erb <p>Dear Sir,</p> <p><b>Pending Indents :<%= @pending_indents %></b>&nbsp;&nbsp;<%= link_to '>>>', "http://www.industryprime.com/notifications/pendi

我想通过SMTP发送自动邮件- daily\u closing.html.erb

 <p>Dear Sir,</p>

 <p><b>Pending Indents :<%= @pending_indents %></b>&nbsp;&nbsp;<%= link_to    '>>>', "http://www.industryprime.com/notifications/pending_indents" %> </p>

<p><b>Overdue Deliveries :<%= @overdue_delivery %></b>&nbsp;&nbsp;<%= link_to '>>>', "http://www.industryprime.com/notifications/pending_purchase_orders" %></p>
<p><b>Unapproved POs: <%= @unapproved_po_count %></b>&nbsp;&nbsp;<%= link_to '>>>', "http://www.industryprime.com/notifications/po_for_approval" %></p>

<p>Yesterday's GRNs</p>

<table border="1">
<thead>
<tr>
  <th>Warehouse</th>
  <th>Date</th>
  <th>Item</th>
  <th>Make/Catno</th>
  <th>UOM</th>
  <th>Qty</th>
  <th>Closing</th>
  <th></th>      
  </tr>
 </thead>


  <tbody>
  <% @grns.each do |grn| %>
    <tr>

    <td><%= grn.warehouse.description %></td>
    <td><%= grn.date.strftime("%d/%m/%y") %></td>
    <td><%= grn.item.description %></td>

    <% if grn.make_id != nil %>
    <td><%= (grn.make.brand.name)+"/"+(grn.make.catno) %></td>
    <%else %>
    <td></td>
    <% end%>

    <td><%= grn.item.uom.shortform %></td>

    <td><%= grn.quantity.round(2) %></td>

    <td><%= grn.balance_quantity.round(2) %></td>
    <%
    if grn.make_id==nil
    params = {
      :item => grn.item_id,
      :make => 0,
      :date => Time.now,
      :warehouse => grn.warehouse_id
    }
    else  
    params = {
      :item => grn.item_id,
      :make => grn.make_id,
      :date => Time.now,
      :warehouse => grn.warehouse_id
    }
    end
    url = "http://www.industryprime.com/stockledgers?#{params.to_query}"
    %>

    <td><%= link_to '>>>', url %></td>

     </tr>
    <% end %>
   </tbody>
 </table>


 <p>Yesterday's ISSUEs</p>

 <table border="1">
  <thead>
   <tr>
  <th>Warehouse</th>
 <th>Date</th>
  <th>Item</th>
  <th>Make/Catno</th>
  <th>UOM</th>
  <th>Qty</th>
  <th>Closing</th>
  <th>To</th>
 <th>Cost Centre</th>      
 <th>CF</th>
 <th></th>
</tr>
  </thead>


  <tbody>
<% @issues.each do |issue| %>
  <tr>

    <td><%= issue.warehouse.description %></td>
    <td><%= issue.date.strftime("%d/%m/%y") %></td>
    <td><%= issue.item.description %></td>


    <% if issue.make_id != nil %>
    <td><%= (issue.make.brand.name)+"/"+(issue.make.catno) %></td>
    <%else %>
    <td></td>
    <% end%>

    <td><%= issue.item.uom.shortform %></td>

    <td><%= issue.quantity.round(2) %></td>

    <td><%= issue.balance_quantity.round(2) %></td>

    <td><%= Issue.find(issue.ref_id).parentissue.worker.name %></td>

    <% group = Costcentre.find(Issue.find(issue.ref_id).costcentre_id)
    @leafgroup=Issue.find(issue.ref_id).costcentre.description
    if group.predecessor !=nil
      @pre=-1
      @leafgroup=""
      @group=group
      until  @pre==0 do
        @leafgroup="." + @group.description+@leafgroup 
        if @pre!=nil
          @group=Costcentre.find_by_id(@group.predecessor)
          if@group==nil
            @pre=0
          else
            @pre=@group.predecessor
          end
        else
          @pre=0
        end
      end
      @leafgroup[0]=""
    end
      %>


    <td><%= @leafgroup %></td>
    <td><%= Issue.find(issue.ref_id).costcentre_frequency %></td>
    <%
    if issue.make_id==nil
    params = {
      :item => issue.item_id,
      :make => 0,
      :date => Time.now,
      :warehouse => issue.warehouse_id
    }
    else  
    params = {
      :item => issue.item_id,
      :make => issue.make_id,
      :date => Time.now,
      :warehouse => issue.warehouse_id
    }
    end
    url = "http://www.industryprime.com/stockledgers?#{params.to_query}"
    %>

    <td><%= link_to '>>>', url %></td>
  </tr>
 <% end %>
 </tbody>
  </table>

 <p>Warm regards,</p>
尊敬的先生:

待定缩进:

逾期交货:

未批准的POs:

昨天的GRNs

仓库 日期 项目 制造/分类号 计量单位 数量 结束 grn.item_id, :make=>0, :date=>Time.now, :仓库=>grn.warehouse\u id } 其他的 参数={ :item=>grn.item\u id, :make=>grn.make\u id, :date=>Time.now, :仓库=>grn.warehouse\u id } 结束 url=”http://www.industryprime.com/stockledgers?#{params.to_query}” %> 昨天的问题

仓库 日期 项目 制造/分类号 计量单位 数量 结束 到 成本中心 查阅 issue.item_id, :make=>0, :date=>Time.now, :warehouse=>issue.warehouse\u id } 其他的 参数={ :item=>issue.item\u id, :make=>issue.make\u id, :date=>Time.now, :warehouse=>issue.warehouse\u id } 结束 url=”http://www.industryprime.com/stockledgers?#{params.to_query}” %> 亲切问候,

当我通过邮件发送此内容时,其显示-

但是我想设计一些css颜色..例如,行bgcolor..和一些邮件内容中不支持的其他颜色。。
我该怎么办?

您需要向该电子邮件添加内嵌css,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>My Mailer</title>
    <style type="text/css">
      body, td { color:#000000; font-size:14px; font-family:Verdana,Helvetica,Arial; }
      #footer { font-size:11px; color:#555555; }
      #footer a { color:#555555;}
    </style>
  </head>
  <body>
    // Your content here
  </body>
</html>

我的邮递员
正文,td{color:#000000;字体大小:14px;字体系列:Verdana、Helvetica、Arial;}
#页脚{字体大小:11px;颜色:#555555;}
#页脚a{color:#555555;}
//你的内容在这里

为了更简单,您还可以使用gem,比如一个。您可以添加内联CSS,但对于每个元素来说,这可能是一项繁琐而艰巨的工作。您可以通过在脚本中包含外部样式表来设置邮件程序的样式。我在项目中使用的是gem。当您安装roadie rails gem时,它将提供两种主要的使用方式:“自动”和“手动”,您可以通过将自动模块包含到邮件程序中来启动自动(请参阅):

在样式表文件夹中添加例如mailer.css并为您的表添加一些类

然后可以在layoutapp/views/layouts/mailer.html.erb中插入mailer.css

<!DOCTYPE html>
<html>
  <head>
     <link rel="stylesheet" type="text/css" href="/assets/mailer.css">   
  </head>

  <body>
    <%= yield %>
  </body>
</html>
Rails.application.config.assets.precompile += %w( mailer.css )
class NewsletterMailer < ApplicationMailer

  include Roadie::Rails::Automatic

  def daily(email)
    mail(to: email, subject: "Welcome to our website!")
  end
end
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <link rel="stylesheet" type="text/css" href="/assets/mailer.css">
  </head>

  <body>
    <%= yield %>
  </body>
</html>
以下是在本地开发人员中使用电子邮件预览的步骤:

# Generate mailer
rails g mailer newsletter_mailer daily
安装2个gems:

   gem 'roadie-rails'   

   # Preview email in the default browser instead of sending it
   group :development do
    gem 'letter_opener' 
   end
在config/environments/development.rb中添加以下代码,以便您可以在浏览器中预览电子邮件,而不是发送:

config.action_mailer.delivery_method = :letter_opener
我们的邮件程序代码app/mailers/newsletter\u mailer.rb

<!DOCTYPE html>
<html>
  <head>
     <link rel="stylesheet" type="text/css" href="/assets/mailer.css">   
  </head>

  <body>
    <%= yield %>
  </body>
</html>
Rails.application.config.assets.precompile += %w( mailer.css )
class NewsletterMailer < ApplicationMailer

  include Roadie::Rails::Automatic

  def daily(email)
    mail(to: email, subject: "Welcome to our website!")
  end
end
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <link rel="stylesheet" type="text/css" href="/assets/mailer.css">
  </head>

  <body>
    <%= yield %>
  </body>
</html>
现在将类添加到我们的app/views/newsletter\u mailer/daily.html.erb文件中:

<h1>Newsletter#daily</h1>

<table class="email-table">
  <tbody>
    <tr class="header-row">
      <td>
        <h1>Welcome User!</h1>
      </td>
    </tr>
    <tr class="body-row">
      <td>
        <p>Thanks for your registering! We appreciate your interest.</p>
      </td>
    </tr>
  </tbody>
</table>
它将用样式化的电子邮件打开新的浏览器窗口


我希望它有助于

使您的邮件具有装饰性的预编译器导轨非常有用

将以下行添加到您的
Gemfile

gem'premailer rails'


阅读完整的文档,包括配置。它的工作原理与常规html完全相似。您只需要使用
样式表链接标签显式地包含
css
文件,或者只需使用
标签即可。

您需要将相关样式表或样式添加到邮件布局中是的,在邮件的html头中定义您的css。欢迎!我很高兴听到它在美国成功了。干杯您好,先生,有一个css样式的问题…….拆信器工作正常,但我不能在没有内联css的情况下进行样式…您能尽快帮助我吗…它部分工作…css类不能在不同的文件中工作。应该放在同一个档案里。我在试着理解你。你仍然有问题吗?是否有任何问题将roadie gem纳入Action Mailer而不是时事通讯Mailer?