summaryrefslogtreecommitdiff
path: root/lib/config/config_ru.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/config/config_ru.rb')
-rw-r--r--lib/config/config_ru.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/config/config_ru.rb b/lib/config/config_ru.rb
index 1d32c7e..3d8dce2 100644
--- a/lib/config/config_ru.rb
+++ b/lib/config/config_ru.rb
@@ -18,3 +18,34 @@ set :raise_errors, true
end
use Rack::ShowExceptions
+if defined?(MAIL)
+
+ # monkeypatch with the original method
+ # strangely enough my mailserver returns "Connection refused - connect(2)" errors without this patch
+ module Rack
+ class MailExceptions
+
+ def send_notification(exception, env)
+ mail = generate_mail(exception, env)
+ smtp = config[:smtp]
+ env['mail.sent'] = true
+ return if smtp[:server] == 'example.com'
+
+ Net::SMTP.start smtp[:server], smtp[:port], smtp[:domain], smtp[:user_name], smtp[:password], smtp[:authentication] do |server|
+ mail.to.each do |recipient|
+ server.send_message mail.to_s, mail.from, recipient
+ end
+ end
+ end
+ end
+ end
+
+
+ require "socket"
+ use Rack::MailExceptions do |mail|
+ mail.to MAIL[:user_name]
+ mail.subject '[ERROR] %s'
+ mail.from "#{Socket.gethostname}@#{MAIL[:domain]}"
+ mail.smtp MAIL
+ end
+end