1

我将我的应用程序从 3.0 升级到 3.1 再到 3.2(根据建议)。所有规范和场景都通过了,他们对发送的电子邮件进行了深入测试。发生的情况是,如果我查看我的电子邮件似乎已发送,maillog并且似乎呈现了正确的模板,但实际上没有邮件发送给用户。

此代码在此应用程序的 3.0 版本中完美运行。我希望有人能发现我错过了什么。我在下面的代码中显示的前几个文件是配置文件。同样,这些东西在以前的部署中运行良好。我很困惑。

“controller mixin”是一个混合到任何想要发送邮件的控制器中的模块。控制器做几乎完全相同的事情,所以我只需要更改邮件和视图。

我很难过如何继续调试它。我知道我可以指定更详细的 smtp 设置,但这之前工作得很好,一旦我在 DNS 中支持它,它就会恢复,而不依赖于特定的主机名。

任何想法都非常感谢!

生产.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

控制器混合(这是在一个模块中,它混合到发送邮件的控制器中):

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
4

0 回答 0