Sha256: 0e292487d58327da6cafe0879af09d6f5b20a6b8c030adf8d08b9ffcc3f56394

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'net/smtp'
require 'mailfactory'

module Flapjack
  module Notifiers

    class Mailer

      def initialize(opts={})
        @from_address = opts[:from_address]
        @website_uri  = opts[:website_uri].gsub(/\/$/, '')
        @log = opts[:logger]
        @log ||= Log4r::Logger.new("notifier")
      end

      def notify(opts={})
        raise unless (opts[:who] && opts[:result])
    
        mail = MailFactory.new
        mail.to = opts[:who].email
        mail.from = @from_address
        mail.subject = "Check: #{opts[:result].id}, Status: #{opts[:result].status}"
        mail.text = <<-DESC
          Check #{opts[:result].id} returned the status "#{opts[:result].status}".
          
          Here was the output: 
            #{opts[:result].output}
    
          You can respond to this issue at:
            #{@website_uri}/issue/#{opts[:result].id}
        DESC

        begin 
          Net::SMTP.start('localhost') do |smtp|
            smtp.sendmail(mail.to_s, mail.from, mail.to)
          end
        rescue Errno::ECONNREFUSED
          @log.error("Couldn't establish connection to mail server!")
        end
      end
    
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
auxesis-flapjack-0.4.6 lib/flapjack/notifiers/mailer/mailer.rb