异常通知的邮件名称是什么?

时间:2014-01-27 12:46:06

标签: ruby-on-rails exception-notification

我的smtp设置和Exception Notification gem有问题。

因为我需要从多个地址发送邮件,所以我使用了这篇文章中描述的设置:

http://justinreid.com/configure-actionmailer-to-use-multiple-smtp-settings/

Ruby(/config/initializers/action_mailer.rb)

module ActionMailer
  class Base
    cattr_accessor :smtp_config

    self.smtp_config = YAML::load(File.open("#{Rails.root}/config/smtp.yml"))[Rails.env]

    def self.smtp_settings
      mailer = self.smtp_config[mailer_name]
      @@smtp_settings = mailer.symbolize_keys
    end

  end
end

YAML(/config/smtp.yml)

common: &common
  address: "smtp.gmail.com"
  port: 587
  authentication: "plain"
  enable_starttls_auto: true

development:
  account_mailer:
    <<: *common,
    domain: "mail.dev.domain.com",
    user_name: "support@dev.domain.com",
    password: "password",
    from: "Domain Support "
  message_mailer:
    <<: *common,
    domain: "mail.messages.dev.domain.com",
    user_name: "messenger@messages.dev.domain.com",
    password: "password",
    from: "Domain Messages "
production:
  account_mailer:
    <<: *common,
    domain: "mail.domain.com",
    user_name: "support@domain.com",
    password: "password",
    from: "Domain Support "
  message_mailer:
    <<: *common,
    domain: "mail.messages.domain.com",
    user_name: "messenger@messages.domain.com",
    password: "password",
    from: "Domain Messages "

在YAML文件中,每个邮件和环境组合都有设置。当我用邮寄邮件发送邮件时,一切运作良好。但是当我尝试使用Exception Notification gem时,我没有收到电子邮件通知,但是我的日志文件中出现了错误消息:

  

使用“email”通知程序发送通知时发生错误。   NoMethodError:未定义的方法symbolize_keys' for nil:NilClass /home/maurice/rails/abmore_server2/config/initializers/action_mailer.rb:9:in smtp_settings'

在我看来,Exception Notification gem有一个自己的邮件程序名称,并试图在smtp.yml中搜索相应的smtp设置,因为它没有定义,所以它找不到它。我试图在gems lib目录中搜索邮件程序名称,但我找不到它,因为我或多或少是新的RoR。

对于您的信息:异常通知配置为:

Ruby(/config/initializers/exception_notification.rb)

AppName::Application.config.middleware.use ExceptionNotification::Rack,
    :ignore_exceptions => [],
  :email => {
    :email_prefix => "development - error: ",
    :sender_address => "username@username.com",
    :exception_recipients => "recipient@recipient.com",
    :delivery_method => :smtp,
    :smtp_settings => {
      :address => "smtp.gmail.com",
      :port => 587,
      :authentication => "plain",
      :user_name => "username@username.com",
      :password => "password",
      enable_starttls_auto: true
    }
  }

我想我必须在此处搜索此文件:https://github.com/smartinez87/exception_notification/blob/master/lib/exception_notifier/email_notifier.rb

有人能告诉我什么是Exception Notification gem的正确邮件名称,以便我可以将它添加到我的smtp.yml文件中吗?

我在我的项目中使用Rails 3.2.x.所以我不能使用new:delivery_method_options。

1 个答案:

答案 0 :(得分:1)

借助调试器gem:https://github.com/cldwalker/debugger和这个railscasts教程:http://railscasts.com/episodes/54-debugging-ruby-revised?autoplay=true我能够自己找到它。邮件程序的名称是“exception_notifier”。