我的应用程序从3.0升级到3.1到3.2(根据建议)。所有规格和场景都通过,他们测试发送的电子邮件非常深入。如果我查看maillog
并且正在显示正确的模板,但实际上没有邮件传递给用户,则会发送电子邮件。
此代码在此应用程序的3.0版本中完美运行。我希望有人能发现我所缺少的东西。我在下面的代码中显示的前几个文件是配置文件。同样,这些东西在之前的部署中运行良好。我很困惑。
“控制器mixin”是一个混合到任何想要发送邮件的控制器的模块。控制器几乎完全一样,所以我需要改变的是邮件和视图。
我很难理解如何进行调试。我知道我可以指定更详细的smtp设置,但之前它运行良好,一旦我在DNS中支持它,而不是依赖于特定的主机名,它就具有弹性。
非常感谢任何想法!
production.rb
# other non-mailer stuff elided.
config.action_mailer.default_url_options = { :host => `hostname` }
ActionMailer::Base.default(:charset => 'utf-8')
ActionMailer::Base.perform_deliveries = true
配置/初始化/为setup_mail.rb
require 'development_mail_interceptor'
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
LIB /为development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "[#{message.to}] #{message.subject}"
message.to = "my.address@gmail.com"
end
end
控制器mixin(这是一个混合到邮件控制器中的模块):
def send_detail_email
@detail_email = @mailer_klass.sent(@ar_obj, session)
end
def send_confirm_email
@confirm_email = @mailer_klass.confirm(@ar_obj, session)
end
def send_email
send_detail_email
# Field naming is inconsistent, so sniff out the contact type
contact_type = ''
contact_type = @ar_obj.contact if @ar_obj.respond_to?(:contact)
contact_type = @ar_obj.best_contact_method if @ar_obj.respond_to?(:best_contact_method)
contact_type = @ar_obj.contact_method if @ar_obj.respond_to?(:contact_method)
# If no contact type, then it's probably assumed a user object's email
contact_type = 'email' if @ar_obj.respond_to?(:user) &&
!@ar_obj.respond_to?(:contact) &&
!@ar_obj.respond_to?(:best_contact_method) &&
!@ar_obj.respond_to?(:contact_method)
send_confirm_email if contact_type == 'email'
end