我试图在我的rails应用程序中创建邮件程序。我相信我已经正确配置了所有内容,但我没有收到电子邮件。
namespace :email do
desc 'Send Daily Summary Email'
task :send_daily_summary, [] => :environment do
DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])
end
end
<% 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 %>
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.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
答案 0 :(得分:2)
您的.deliver
电话中缺少DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS'])
。
应该是:
DailyMailer.summary_email(ENV['GROUP_MAIL_ADDRESS']).deliver