Sha256: 7e1295206bfe6d78c6144b3f6370bf9349fd34e2a0a49df25a6ed714cf207713

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'mail'

module Hippo

    module Mailer
        class << self

            def create
                config = SystemSettings.for_ext(:smtp)
                delivery = delivery_method_config(config)
                Mail::Message.new do
                    from "\"#{config['from_name']}\" <#{config['from_email']}>"
                    delivery_method delivery[:via], delivery[:config]
                end
            end

            def delivery_method_config(config)
                config = Hippo.config.secrets.smtp || {}
                {
                    via: Hippo.env.production? ? :smtp : :test,
                    config: {
                        address: config['address'],
                        user_name: config['user_name'],
                        password: config['password'],
                        enable_starttls_auto: true,
                        port: 587
                    }
                }
            end

            def from_template(template)
                mail = create
                mail.content_type = 'text/html; charset=UTF-8'
                mail.body = template.render
                mail.to = template.to
                mail.subject = template.subject
                mail
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hippo-fw-0.9.7 lib/hippo/mailer.rb
hippo-fw-0.9.6 lib/hippo/mailer.rb
hippo-fw-0.9.5 lib/hippo/mailer.rb