在rails项目中,用Exception Notification,可以在程序异常时发送通知邮件。
1.安装gem
gem 'exception_notification', :require => 'exception_notifier'
并bundle install
2.安装Exception Notification
在config/initializers/下新建exception_notificatioin.rb文件
AppName::Application.config.middleware.use ExceptionNotifier,
:email_prefix => "[Title] ",
:sender_address => %{"notifier" <notifier@example.com>},
:exception_recipients => %w{send_to@example.com}
如果是开发模式下测试,需要在config/environments/development.rb中配置
config.action_mailer.raise_delivery_errors = true
3.安装邮件代理类库(在ubuntu下)
sudo apt-get install sendmail