Sha256: 0d433bfca8e15026284c6a97fdf46f0188e76e55084998a98171ca7a031fef2b

Contents?: true

Size: 1.38 KB

Versions: 21

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

require 'net/smtp'
require 'tmail'

module Flapjack
  module Notifiers

    class Mailer

      attr_accessor :log, :from_address

      def initialize(opts={})
        @log = opts[:log]
        @from_address = opts[:from_address]
        @website_uri = opts[:website_uri]

        raise ArgumentError, "from address must be provided" unless @from_address
      end

      def notify(opts={})
        raise ArgumentError, "a recipient was not specified" unless opts[:who]
        raise ArgumentError, "a result was not specified" unless opts[:result]

        # potential FIXME: refactor TMail out entirely?
        mail = TMail::Mail.new
        mail.to = opts[:who].email
        mail.from = @from_address
        mail.subject = "Check: #{opts[:result].check_id}, Status: #{opts[:result].status}"
        mail.body = <<-DESC
          Check #{opts[:result].check_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].check_id}
        DESC

        begin
          Net::SMTP.start('localhost') do |smtp|
            return 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

21 entries across 21 versions & 1 rubygems

Version Path
flapjack-0.6.43 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.42 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.41 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.40 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.39 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.38 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.37 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.36 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.35 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.34 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.33 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.32 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.31 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.30 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.29 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.28 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.27 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.26 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.25 lib/flapjack/notifiers/mailer/mailer.rb
flapjack-0.6.24 lib/flapjack/notifiers/mailer/mailer.rb