Sha256: 092b1b3a17099fed2858e7fd39ede771e2c24cb1988194f7206155f98760ae11

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'rubygems'
gem 'activesupport', '~>2.0'
gem 'actionpack', '~>2.0'
gem 'actionmailer', '~> 2.0' 
require 'action_mailer'
require 'cerberus/publisher/base'

if RUBY_VERSION =~ /1\.8\.\d/
  # This hack works only on 1.8.x
  require 'cerberus/publisher/netsmtp_tls_fix'
end

class Cerberus::Publisher::Mail < Cerberus::Publisher::Base
  def self.publish(state, manager, options)
    mail_opts = options[:publisher, :mail].dup
    raise "There is no recipients provided for mail publisher" unless mail_opts[:recipients]

    configure(mail_opts)
    ActionMailerPublisher.deliver_message(state, manager, options)
  end

  private
  def self.configure(config)
    [:authentication, :delivery_method].each do |k|
      config[k] = config[k].to_sym if config[k]
    end

    ActionMailer::Base.delivery_method = config[:delivery_method] if config[:delivery_method]
    ActionMailer::Base.smtp_settings = config
  end

  class ActionMailerPublisher < ActionMailer::Base
    def message(state, manager, options)
      @subject, @body = Cerberus::Publisher::Base.formatted_message(state, manager, options)
      @recipients, @sent_on = options[:publisher, :mail, :recipients], Time.now
      @from = options[:publisher, :mail, :sender] || 'cerberus@example.com' 
      raise "Please specify recipient addresses for application '#{options[:application_name]}'" unless @recipients
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cerberus-0.8.0 lib/cerberus/publisher/mail.rb
cerberus-0.7.9 lib/cerberus/publisher/mail.rb