Sha256: 9e53f729a4931ec39dd6a7090b25a1dfe4ba0c403ac1e7488f9289e7aaba2201

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

require 'net/smtp'

module Ring
class SQA
class Alarm

  class Email
    SERVER = 'localhost'

    def send opts
      short, long = opts[:short], opts[:long]
      @from     = CFG.email.from
      @to       = [CFG.email.to].flatten
      prefix    = CFG.email.prefix? ? CFG.email.prefix : ''
      @subject  = prefix + short
      @reply_to = CFG.email.reply_to? ? CFG.email.reply_to : @from
      @body     = long
      send_email compose_email
    rescue => error
      Log.error "Email raised '#{error.class}' with message '#{error.message}'"
    end

    private

    def compose_email
      mail = []
      mail << 'From: '     + @from
      mail << 'To: '       + @to.join(', ')
      mail << 'Reply-To: ' + @reply_to
      mail << 'Subject: '  + @subject
      mail << 'List-Id: '  + 'ring-sqa <sqa.ring.nlnog.net>'
      mail << 'X-Mailer: ' + 'ring-sqa'
      mail << ''
      mail = mail.join("\n")
      mail+@body
    end

    def send_email email
      Net::SMTP.start('localhost') do |smtp|
        smtp.send_message email, @from, @to
      end
    end
  end

end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ring-sqa-0.3.1 lib/ring/sqa/alarm/email.rb
ring-sqa-0.3.0 lib/ring/sqa/alarm/email.rb
ring-sqa-0.2.2 lib/ring/sqa/alarm/email.rb
ring-sqa-0.2.1 lib/ring/sqa/alarm/email.rb
ring-sqa-0.2.0 lib/ring/sqa/alarm/email.rb
ring-sqa-0.1.12 lib/ring/sqa/alarm/email.rb