添加 Gem
gem 'exception_notification'
配置
在 production.rb 里面配置邮件和添加 exception_notificaiton 配置
# 配置邮件
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: 'smtp.163.com',
port: 25,
domain: '163.com',
user_name: 'sender_email@163.com',
password: 'sender_password',
authentication: :login,
enable_starttls_auto: false }
ActionMailer::Base.default :from => "notify <sender_email@163.com>"
default_url_options[:host] = 'example.com'
config.action_mailer.default_url_options = { :host => 'example.com' }
# 配置异常通知
Rails.application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[xxx bug汇报] ",
:sender_address => %{"notify" <sender@163.com>},
:exception_recipients => %w{receive1@163.com receive2@163.com},
:sections => %w{request session environment backtrace}
}