Sha256: ca14df3307916d97c43081ff417a18b311cd6ebc4825e7d256737c041f8b21db

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module ActiveWrapper
  class Mail
    
    attr_reader :base, :env, :config
    
    def initialize(options)
      @base = options[:base]
      @env = options[:env].to_s
      
      path = "#{base}/config/mail.yml"
      
      if File.exists?(path)
        @config = YAML::load(File.open(path))
        if @config && @config = @config[@env]
          
          @config = @config.to_options
          @config[:imap] = @config[:imap].to_options if @config[:imap]
          @config[:smtp] = @config[:smtp].to_options if @config[:smtp]
          if @config[:smtp]
            ActionMailer::Base.delivery_method = :smtp
            ActionMailer::Base.smtp_settings = @config[:smtp]
          end
        end
      end
    end
    
    def deliver(options)
      Mailer.deliver_email(options)
    end
    
    class Mailer < ActionMailer::Base
      def email(options)
        from        options[:from]
        recipients  options[:to]
        subject     options[:subject]
        body        options[:body]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
winton-active_wrapper-0.1.2 lib/active_wrapper/mail.rb