Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replaced TMail with Mail in MailExceptions

  • Loading branch information...
commit 94ba52d7816d2b3de94289336f64fa5925792502 1 parent 9f5bcdd
Carl Hörberg authored

Showing 1 changed file with 15 additions and 34 deletions. Show diff stats Hide diff stats

  1. +15 34 lib/rack/contrib/mailexceptions.rb
49 lib/rack/contrib/mailexceptions.rb
... ... @@ -1,5 +1,5 @@
1 1 require 'net/smtp'
2   -require 'tmail'
  2 +require 'mail'
3 3 require 'erb'
4 4
5 5 module Rack
@@ -14,10 +14,10 @@ def initialize(app)
14 14 @app = app
15 15 @config = {
16 16 :to => nil,
17   - :from => ENV['USER'] || 'rack',
  17 + :from => ENV['USER'] || 'rack@localhost',
18 18 :subject => '[exception] %s',
19 19 :smtp => {
20   - :server => 'localhost',
  20 + :address => 'localhost',
21 21 :domain => 'localhost',
22 22 :port => 25,
23 23 :authentication => :login,
@@ -34,8 +34,6 @@ def call(env)
34 34 begin
35 35 @app.call(env)
36 36 rescue => boom
37   - # TODO don't allow exceptions from send_notification to
38   - # propogate
39 37 send_notification boom, env
40 38 raise
41 39 end
@@ -53,41 +51,24 @@ def smtp(settings={})
53 51
54 52 private
55 53 def generate_mail(exception, env)
56   - mail = TMail::Mail.new
57   - mail.to = Array(config[:to])
58   - mail.from = config[:from]
59   - mail.subject = config[:subject] % [exception.to_s]
60   - mail.date = Time.now
61   - mail.set_content_type 'text/plain'
62   - mail.charset = 'UTF-8'
63   - mail.body = @template.result(binding)
64   - mail
  54 + mail = Mail.new({
  55 + :from => config[:from],
  56 + :to => config[:to],
  57 + :subject => config[:subject] % [exception.to_s],
  58 + :body => @template.result(binding)
  59 + })
65 60 end
66 61
67 62 def send_notification(exception, env)
68 63 mail = generate_mail(exception, env)
69 64 smtp = config[:smtp]
  65 + # for backward compability, replace the :server key with :address
  66 + address = smtp.delete :server
  67 + smtp[:address] = address if address
  68 + mail.delivery_method :smtp, smtp
  69 + mail.deliver!
70 70 env['mail.sent'] = true
71   - return if smtp[:server] == 'example.com'
72   -
73   - server = service.new(smtp[:server], smtp[:port])
74   -
75   - if smtp[:enable_starttls_auto] == :auto
76   - server.enable_starttls_auto
77   - elsif smtp[:enable_starttls_auto]
78   - server.enable_starttls
79   - end
80   -
81   - server.start smtp[:domain], smtp[:user_name], smtp[:password], smtp[:authentication]
82   -
83   - mail.to.each do |recipient|
84   - server.send_message mail.to_s, mail.from, recipient
85   - end
86   - end
87   -
88   - def service
89   - Net::SMTP
90   - end
  71 + end
91 72
92 73 def extract_body(env)
93 74 if io = env['rack.input']

0 comments on commit 94ba52d

Please sign in to comment.
Something went wrong with that request. Please try again.