Module: Hippo::Mailer

Defined in:
lib/hippo/mailer.rb

Class Method Summary collapse

Class Method Details

.createObject



8
9
10
11
12
13
14
15
# File 'lib/hippo/mailer.rb', line 8

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

.delivery_method_config(config) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hippo/mailer.rb', line 17

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

.from_template(template) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/hippo/mailer.rb', line 31

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