ActionMailer 不发送电子邮件
ActionMailer not sending email
我正在尝试在我的 rails 应用程序中创建一个邮件程序。我相信我已正确配置所有内容,但我没有收到电子邮件。
app/lib/tasks/email/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
app/views/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 %>
app/mailers/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
config/environments/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" = 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
您的 DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])
电话未接 .deliver
。
应该是:
DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS']).deliver
我正在尝试在我的 rails 应用程序中创建一个邮件程序。我相信我已正确配置所有内容,但我没有收到电子邮件。
app/lib/tasks/email/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
app/views/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 %>
app/mailers/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
config/environments/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" = 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
您的 DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])
电话未接 .deliver
。
应该是:
DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS']).deliver