【问题标题】:Whenever Gem Daily email using actionmailer not sending每当使用 actionmailer 的 Gem Daily 电子邮件不发送
【发布时间】:2016-05-15 05:06:48
【问题描述】:

我似乎无法让每当 gem 与我的 actionmailer 一起工作。我正在尝试运行开发中的应用程序,其中将在特定时间向特定个人发送电子邮件。

在我的 schedule.rb 文件中,我有以下内容:

every :day, :at => '12:48pm' do
  runner "FoodPlan.food_email"
end

在我的名为 food_plans_controller.rb 的控制器中,我有:

  def self.food_email
    @food_plans = FoodPlan.where(food_plan_date: Date.today).order('meal ASC')

    UserMailer.food_email(@food_plans).deliver_now
  end

在 user_mailer.rb 我有(注意我出于隐私原因删除了电子邮件):

  def food_email (food)
    @food_plans = food

    mail(to: '---------@yahoo.com', subject: 'Food Orders for #{Date.today}')
  end

我在视图中有一个名为 user_mailer 的文件夹,里面有一个名为 food_email.html.erb 的文件,其 ff:

<!DOCTYPE html>
<html>    
</head>
  <body>
    <h1>title</h1>
    <p>
      Good morning, -----!
      <br><br>
      Meal Plans for <%=Date.today%>:
      <br><br>
      <table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>#</th>
      <th>Meal Plan</th>
      <th>Ordered by</th>
      <th>Room Number</th>
      <th>Received by</th>
      <th>Signature</th>
    </tr>
  </thead>

  <tbody>
    <%countint=1%>
    <% @food_plans.each do |food_plan| %>
      <tr>
        <td><%=countint%></td>
        <td><%= food_plan.meal %></td>
        <td><%=food_plan.applicant.first_name%>
        <%=food_plan.applicant.last_name%></td>
        <td><%=food_plan.applicant.room_number%></td>
        <%countint+=1%>
        <td></td>
        <td></td>
      </tr>
    <% end %>


  </tbody>
</table>
      <br>
      <br>
      ---.
      <br>
      <br>
      If you have any concerns, don't hesitate to call us at ------.

      <br>
      <br>
      Thanks, <br>----
    </p>
  </body>
</html> 

在我的开发配置中(我删除了电子邮件和密码):

  config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'example.com',
  user_name:            '-------',
  password:             '-------',
  authentication:       'plain',
  enable_starttls_auto: true  }

我已尝试阅读此guide,但我仍然无法让 gem 与 actionmailer 一起使用。我还阅读了when gem 的documentation,但我仍然无法弄清楚我做错了什么。 :(

我没有收到任何错误,只是电子邮件没有发送。

【问题讨论】:

  • 具体什么不起作用以及您遇到什么问题?你有错误吗?即使您希望它发送,邮件是否也没有发送?
  • 电子邮件未发送。我认为它甚至不会进入调度程序。我正在查看本地主机终端的日志,即使在我在调度程序中指定的时间内,日志也没有任何更改。

标签: ruby-on-rails ruby actionmailer whenever


【解决方案1】:

我猜你的规则从来没有到达本地crontab,因此从未真正运行过。每当 gem 规则不让系统自行运行命令时,它们只是 cron 规则的 ruby 表示法,驻留在类 unix 系统上的 /etc/crontab(或类似规则)中.

when gem 在部署期间自动更新crontab(使用capistrano plugin),因此您的规则应该在生产服务器上有效。

但是,在开发主机上,您需要手动更新您的 crontab (credits):

whenever --update-crontab --set environment='development'

要查看crontab 中的当前内容,请使用cat /etc/crontab。您的规则(在任何时候定义)应该在您更新后出现在文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    相关资源
    最近更新 更多