Sha256: 95c4ba128d761706e21f85b740fd5d6a0b1f09dbd32fe90c8a607d9c3c03f575
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 KB
Contents
begin require 'mail' rescue LoadError => e puts "Please install mail gem: gem install mail" raise end module Outpost module Notifiers # The Email notifier issues Outpost notifications to through email. It # uses the 'mail' gem send the emails. You can see mail's documentation # in order to change how emails will be delivered: # https://github.com/mikel/mail # # This requires the 'mail' gem to be installed. class Email # @param [Hash] Options to create an email notification. # @option options [String] :from The "from" email field # @option options [String] :to Where e-mails will be delivered # @option options [String] :subject The email's subject def initialize(options={}) @from = options[:from] @to = options[:to] @subject = options[:subject] || 'Outpost notification' @delivery_method = options[:delivery_method] || [] unless @from && @to raise ArgumentError, 'You need to set :from and :to to send emails.' end end # Issues a notification through email. This is a callback, called by # an Outpost instance. # @param [Outpost::Application, #read] outpost an instance of an outpost, containing # latest status, messages and reports that can be queried to build # a notification message. def notify(outpost) mail = Mail.new mail.from = @from mail.to = @to mail.subject = @subject mail.body = build_message(outpost) mail.send(:delivery_method, *@delivery_method) unless @delivery_method.empty? mail.deliver end private def build_message(outpost) status = outpost.last_status.to_s message = "This is the report for #{outpost.name}: " message += "System is #{status.upcase}!\n\n" message += outpost.messages.join("\n") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
outpost-0.2.5 | lib/outpost/notifiers/email.rb |