我对ActionMailer有一个奇怪的问题。它发送的是一些邮件而不是其他邮件。我们最近升级到3.2.12,那就是故障开始的时候。
这是我的配置:
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
# config.action_mailer.perform_deliveries = false
config.action_mailer.default_url_options = { :host => "ruby.ourdomain.com/app" }
config.action_mailer.asset_host = "http://ruby.ourdomain.com/app"
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "pop.ourdomain.com"
}
此邮件程序工作:
在模型中:
def alertStudent
AbsenceMailer.StudentAbsenceAlert(self).deliver
end
邮件:
def StudentAbsenceAlert(alert)
@alert = alert
@student = studentInfo(@alert.student_id)
@advisor = staffInfo(@alert.advisor)
@instructor = @alert.polling.instructor
studentAddr = @student['STUDENT_EMAIL']
mail to: studentAddr, cc: @advisor['STAFF_EMAIL'], from: @advisor['STAFF_EMAIL'], subject: "[#{@alert.polling.course}] You have been marked absent #{Time.now.strftime('%m-%e-%Y')}"
end
此邮件程序无法正常工作并且不会引起错误:
模特:
def self.advisorDigest
AbsenceAlert.current_status('active').advisor_day.group_by{|r| r.advisor }.each do |id, alerts|
AbsenceMailer.AdvisorAbsenceDigest(id, alerts).deliver
end
end
邮件:
def AdvisorAbsenceDigest(id, alerts)
@alerts = alerts
@staff = staffInfo(id)
mail to: @staff['STAFF_EMAIL'], subject: "Student Absence Report #{Time.now.strftime('%m-%e-%Y')}"
puts "[#{Time.now.strftime('%c')}] Sent Advisor Digest: #{alerts.count} alerts to #{@staff['STAFF_EMAIL']}"
end
在日志中,我看到以下
Rendered absence_mailer/AdvisorAbsenceDigest.html.haml within layouts/app (31.6ms)
然而它实际上并没有发送邮件。
为了成功通话,我通常会看到
Sent mail to email@ourdomain.com (193ms)
紧跟视图渲染之后,在我看到失败的情况下,我没有得到它。
我启用了投放错误,并且没有收到任何错误。我们的应用程序没有改变,我们的配置没有改变。我们唯一做的就是升级到rails 3.2.12并且第二封邮件已经开始失败。
答案 0 :(得分:2)
仍然不确定为什么一个人在工作而另一个人没有工作,但我能够通过将.deliver
移出模型并进入邮件程序来纠正这个问题,例如:
模特:
def self.advisorDigest
AbsenceAlert.current_status('active').advisor_day.group_by{|r| r.advisor }.each do |id, alerts|
AbsenceMailer.AdvisorAbsenceDigest(id, alerts)
end
end
邮件:
def AdvisorAbsenceDigest(id, alerts)
@alerts = alerts
@staff = staffInfo(id)
mail(to: @staff['STAFF_EMAIL'], subject: "Student Absence Report #{Time.now.strftime('%m-%e-%Y')}").deliver
puts "[#{Time.now.strftime('%c')}] Sent Advisor Digest: #{alerts.count} alerts to #{@staff['STAFF_EMAIL']}"
end