<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,8 +16,10 @@ Configuration goes in your projects `config/init.rb` file inside `Merb::BootLoad
       :web_hooks       =&gt; ['http://example.com'],
       :email_addresses =&gt; ['hello@exceptions.com', 'user@myapp.com'],
       :app_name        =&gt; &quot;My App Name&quot;,
+      :environments    =&gt; ['production', 'staging'],
       :email_from      =&gt; &quot;exceptions@myapp.com&quot;,
-      :environments    =&gt; ['production', 'staging']
+      :mailer_config =&gt; nil,
+      :mailer_delivery_method =&gt; :sendmail
     }
 
 The plugin now automatically includes itself into your Exceptions controller. If you are using an old version of this plugin, you can remove the include from your Exceptions controller.
@@ -40,6 +42,10 @@ Settings
 
 `environments`: Notifications will only be sent for environments in this list, defaults to `production`
 
+`mailer_delivery_method`: The delivery method for notifications mailer, see merb-mailer documentation.
+
+`mailer_config`: A hash of configuration options for the notifications mailer, see merb-mailer documentation.
+
 Advanced usage
 --------------
 merb-exceptions will deliver exceptions for any unhandled exceptions (exceptions that do not have views defined in the `Exceptions` controller)</diff>
      <filename>merb-exceptions/README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -1,20 +1,23 @@
 # make sure we're running inside Merb
 if defined?(Merb::Plugins)
 
-  # Default configuration
-  Merb::Plugins.config[:exceptions] = {
-    :web_hooks       =&gt; [],
-    :email_addresses =&gt; [],
-    :app_name        =&gt; &quot;Merb awesome Application&quot;,
-    :email_from      =&gt; &quot;exceptions@app.com&quot;,
-    :environments    =&gt; ['production']
-  }.merge(Merb::Plugins.config[:exceptions] || {})
-
   Merb::BootLoader.before_app_loads do
 
   end
 
   Merb::BootLoader.after_app_loads do
+
+    # Default configuration
+    Merb::Plugins.config[:exceptions] = {
+      :web_hooks       =&gt; [],
+      :email_addresses =&gt; [],
+      :app_name        =&gt; &quot;Merb awesome Application&quot;,
+      :environments    =&gt; ['production'],
+      :email_from      =&gt; &quot;exceptions@myapp.com&quot;,
+      :mailer_config =&gt; nil,
+      :mailer_delivery_method =&gt; :sendmail
+    }.merge(Merb::Plugins.config[:exceptions] || {})
+
     if Object.const_defined?(:Exceptions)
       Exceptions.send(:include, MerbExceptions::ExceptionsHelper)
     end</diff>
      <filename>merb-exceptions/lib/merb-exceptions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,20 @@
 require 'net/http'
 require 'uri'
-require &quot;erb&quot;
+require 'erb'
+require 'merb-mailer'
 
 module MerbExceptions
   class Notification
+
+    class Mailer &lt; Merb::Mailer
+    end
+
     attr_reader :details
 
     def initialize(details = nil)
-      @details = details || {}
-      @config = Merb::Plugins.config[:exceptions]
+      @details = details || []
+      Mailer.config = Merb::Plugins.config[:exceptions][:mailer_config]
+      Mailer.delivery_method = Merb::Plugins.config[:exceptions][:mailer_delivery_method]
     end
 
     def deliver!
@@ -17,7 +23,6 @@ module MerbExceptions
     end
 
     def deliver_web_hooks!
-      return unless should_deliver_notifications?
       Merb.logger.info &quot;DELIVERING EXCEPTION WEB HOOKS&quot;
       web_hooks.each do |address|
         post_hook(address)
@@ -25,10 +30,9 @@ module MerbExceptions
     end
 
     def deliver_emails!
-      return unless should_deliver_notifications?
       Merb.logger.info  &quot;DELIVERING EXCEPTION EMAILS&quot;
       email_addresses.each do |address|
-        send_notification_email(address)
+        send_email(address)
       end
     end
 
@@ -38,13 +42,8 @@ module MerbExceptions
 
     def environments; option_as_array(:environments); end
 
-
-    def should_deliver_notifications?
-      environments.include? Merb.env
-    end
-
-
     def params
+      @params ||=
       {
         'request_url'              =&gt; details['url'],
         'request_controller'       =&gt; details['params'][:controller],
@@ -52,7 +51,7 @@ module MerbExceptions
         'request_params'           =&gt; details['params'],
         'environment'              =&gt; details['environment'],
         'exceptions'               =&gt; details['exceptions'],
-        'app_name'                 =&gt; @config[:app_name]
+        'app_name'                 =&gt; Merb::Plugins.config[:exceptions][:app_name]
       }
     end
 
@@ -65,31 +64,29 @@ module MerbExceptions
       Net::HTTP.post_form( uri, params ).body
     end
 
-    def send_email(address, body)
+    def email_body
+      @body ||= begin
+        path = File.join(File.dirname(__FILE__), 'templates', 'email.erb')
+        template = Erubis::Eruby.new(File.open(path,'r') { |f| f.read })
+        template.result(binding)
+      end
+    end
+
+    def send_email(address)
       Merb.logger.info &quot;- emailing to #{address}&quot;
-      email = Merb::Mailer.new({
+      email = Mailer.new({
         :to =&gt; address,
-        :from =&gt; @config[:email_from],
-        :subject =&gt; &quot;[#{@config[:app_name]} EXCEPTION]&quot;,
-        :text =&gt; body
+        :from =&gt; Merb::Plugins.config[:exceptions][:email_from],
+        :subject =&gt; &quot;[#{Merb::Plugins.config[:exceptions][:app_name]} EXCEPTION]&quot;,
+        :text =&gt; email_body
       })
       email.deliver!
     end
 
-    def send_notification_email(address)
-      send_email(address, plain_text_mail_body)
-    end
-
-    def plain_text_mail_body
-      path = File.join(File.dirname(__FILE__), 'templates', 'email.erb')
-      template = Erubis::Eruby.new(File.open(path,'r') { |f| f.read })
-      template.result(binding)
-    end
-
     # Used so that we can accept either a single value or array (e.g. of
     # webhooks) in our YAML file.
     def option_as_array(option)
-      value = @config[option]
+      value = Merb::Plugins.config[:exceptions][option]
       case value
       when Array
         value.reject { |e| e.nil? } # Don't accept nil values</diff>
      <filename>merb-exceptions/lib/merb-exceptions/notification.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,37 +8,40 @@ describe MerbExceptions::Notification do
     it &quot;should create a new notification without errors&quot; do
       lambda { Notification.new(mock_details) }.should_not raise_error
     end
-    
+
     it &quot;should set the detail values to those provided&quot; do
       Notification.new(mock_details).details.should == mock_details
     end
   end
-  
+
   describe &quot;.deliver!&quot; do
     before :each do
       @notification = Notification.new(mock_details)
-      @notification.stub!('deliver_emails!')
       @notification.stub!('deliver_web_hooks!')
     end
-    
+
+    after :each do
+      Notification::Mailer.deliveries.clear
+    end
+
     it &quot;should deliver web hooks&quot; do
       @notification.should_receive('deliver_web_hooks!')
       @notification.deliver!
     end
 
     it &quot;should deliver emails&quot; do
-      @notification.should_receive('deliver_emails!')
+      Notification::Mailer.deliveries.length.should == 0
       @notification.deliver!
+      Notification::Mailer.deliveries.length.should == 2
     end
   end
-  
+
   describe &quot;.deliver_web_hooks!&quot; do
     before :each do
-      mock_merb_config({:web_hooks =&gt; ['http://www.test1.com', 'http://www.test2.com']})
       @notification = Notification.new(mock_details)
       @notification.stub!(:post_hook)
     end
-    
+
     it &quot;should call post_hook for each url&quot; do
       @notification.should_receive(:post_hook).
         once.with('http://www.test1.com')
@@ -50,35 +53,17 @@ describe MerbExceptions::Notification do
 
   describe &quot;.deliver_emails!&quot; do
     before :each do
-      mock_merb_config({:email_addresses =&gt; ['user1@test.com', 'user2@test.com']})
       @notification = Notification.new(mock_details)
-      @notification.stub!(:send_notification_email)
+      Notification::Mailer.deliveries.clear
     end
 
     it &quot;should call send_notification_email for each address&quot; do
-      @notification.should_receive(:send_notification_email).
-        once.with('user1@test.com')
-      @notification.should_receive(:send_notification_email).
-        once.with('user2@test.com')
       @notification.deliver_emails!
+      Notification::Mailer.deliveries.first.to.should include(&quot;user1@test.com&quot;)
+      Notification::Mailer.deliveries.first.from.should include(&quot;exceptions@myapp.com&quot;)
+      Notification::Mailer.deliveries.last.to.should include(&quot;user2@test.com&quot;)
+      Notification::Mailer.deliveries.first.text.should == Notification::Mailer.deliveries.last.text
     end
   end
-  
-  # Running tests with test environment
-  describe &quot;.should_deliver_notifications?&quot; do
-    it &quot;should return true if the current environment is on the config[:environments] list of one item&quot; do
-        mock_merb_config({ :environments =&gt; 'test' })
-        Notification.new(mock_details).should_deliver_notifications?.should be_true
-    end
-    
-    it &quot;should return true if the current environment is on the config[:environments] list as an array&quot; do
-        mock_merb_config({ :environments =&gt; ['staging', 'test'] })
-        Notification.new(mock_details).should_deliver_notifications?.should be_true
-    end
 
-    it &quot;should return false if the current environment is not on the config[:environments] list&quot; do
-        mock_merb_config({ :environments =&gt; ['staging', 'development'] })
-        Notification.new(mock_details).should_deliver_notifications?.should be_false
-    end
-  end
 end</diff>
      <filename>merb-exceptions/spec/notification_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,12 @@ class Exceptions &lt; Application
   end
 end
 
-Merb::Plugins.config[:exceptions][:environments] = 'test'
+Merb::Plugins.config[:exceptions] = {
+  :email_addresses =&gt; ['user1@test.com', 'user2@test.com'],
+  :web_hooks =&gt; ['http://www.test1.com', 'http://www.test2.com'],
+  :environments    =&gt; ['test'],
+  :mailer_delivery_method =&gt; :test_send
+}
 Merb.start :environment =&gt; 'test'
 
 module Merb
@@ -81,14 +86,10 @@ end
 module NotificationSpecHelper
   def mock_details(opts={})
     {
-      'exception'      =&gt; {},
+      'exceptions'      =&gt; [],
       'params'         =&gt; { :controller=&gt;'errors', :action=&gt;'show' },
       'environment'    =&gt; { 'key1'=&gt;'value1', 'key2'=&gt;'value2' },
       'url'            =&gt; 'http://www.my-app.com/errors/1'
     }.merge(opts)
   end
-
-  def mock_merb_config(opts={})
-    Merb::Plugins.config[:exceptions].merge!(opts)
-  end
 end
\ No newline at end of file</diff>
      <filename>merb-exceptions/spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>adf68ee6244a11d3eceafd18caa8156f600bbdd3</id>
    </parent>
  </parents>
  <author>
    <name>Wesley Beary</name>
    <email>monki@geemus.com</email>
  </author>
  <url>http://github.com/wycats/merb/commit/4b8f0b82451956369766f3d0a92c98a4a9c03308</url>
  <id>4b8f0b82451956369766f3d0a92c98a4a9c03308</id>
  <committed-date>2008-11-06T07:27:23-08:00</committed-date>
  <authored-date>2008-11-05T00:31:48-08:00</authored-date>
  <message>non stub tests for emailing, better configuration options</message>
  <tree>48e12dc07635da91db0ac3de334e706f99c18d7b</tree>
  <committer>
    <name>Matt Aimonetti</name>
    <email>mattaimonetti@gmail.com</email>
  </committer>
</commit>
