ActionMailer不发送电子邮件

时间:2015-03-06 17:33:04

标签: ruby-on-rails ruby ruby-on-rails-4 gmail actionmailer

我试图在我的rails应用程序中创建邮件程序。我相信我已经正确配置了所有内容,但我没有收到电子邮件。

的应用程序/ LIB /任务/电子邮件/ daily_summary.rake

namespace :email do
  desc 'Send Daily Summary Email'
  task :send_daily_summary, [] => :environment do
    DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])
  end
end

的应用程序/视图/ daily_mailer / summary_email.html.erb

<% if @new_apps.count >= 1 %>
<h1>
  <%="#{@new_apps.count} new Applications were added today" %>
</h1>
  <% @new_apps.each do |app| %>
    <p>
      <%= image_tag app.icon_url %>
    </p>
    <p>
      <%= app.name %>
    </p>
    <p>
      <%= app.last_build %>
    </p>
  <% end %>
<% end %>
<% if @new_versions.count >= 1 %>
<h1>
  <%="#{@new_versions.count} new builds of Applications were added." %>
</h1>
  <% @new_versions.each do |version| %>
    <p>
      <%= image_tag version.icon_url %>
    </p>
    <p>
      <%= version.app_name %>
    </p>
    <p>
      <%= version.build_number %>
    </p>
  <% end %>
<% end %>

的应用程序/邮寄者/ daily_mailer.rb

class DailyMailer < ApplicationMailer
  def summary_email(email_address)
    @new_versions = Version.since(24.hours.ago)
    @new_apps = App.since(24.hours.ago)
    mail(to: email_address, subject: 'Daily Summary - ')
  end
end

配置/环境/ development.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               ###############,
    user_name:            ENV['EMAIL_LOGIN'],
    password:             ENV['EMAIL_PASSWORD'],
    authentication:       'plain',
    enable_starttls_auto: true  }

输出

rake email:send_daily_summary
    (0.7ms)  SELECT COUNT(*) FROM "apps"  WHERE (created_at > '2015-03-05 17:13:12.405508')
    (1.0ms)  SELECT COUNT(*) FROM "versions"  WHERE (created_at > '2015-03-05 17:13:12.345107')
    (0.4ms)  SELECT COUNT(*) FROM "versions"  WHERE (created_at > '2015-03-05 17:13:12.345107')
   Version Load (0.6ms)  SELECT "versions".* FROM "versions"  WHERE (created_at > '2015-03-05 17:13:12.345107')
   App Load (0.4ms)  SELECT  "apps".* FROM "apps"  WHERE "apps"."id" = $1 LIMIT 1  [["id", 18]]
   Rendered daily_mailer/summary_email.html.erb within layouts/mailer (97.8ms)

DailyMailer#summary_email: processed outbound mail in 440.8ms

1 个答案:

答案 0 :(得分:2)

您的.deliver电话中缺少DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])

应该是:

DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS']).deliver