Module: Hippo::Mailer

Defined in:
lib/hippo/mailer.rb

Defined Under Namespace

Classes: TestMailer

Class Method Summary collapse

Class Method Details

.createObject


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

def create
    config = SystemSettings.for_ext(:smtp)
    delivery_config = delivery_method_config(config)
    Mail::Message.new do
        from "\"#{config['from_name']}\" <#{config['from_email']}>"
        if Hippo.env.production?
            delivery_method :smtp, delivery_config
        else
            delivery_method TestMailer, delivery_config
        end
    end
end

.delivery_method_config(config) ⇒ Object


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

def delivery_method_config(config)
    Hippo::Tenant.system.perform do
        config = Hippo.config.secrets.smtp || {}
        {
            address: config['address'],
            user_name: config['user_name'],
            password: config['password'],
            enable_starttls_auto: true,
            port: 587
        }
    end
end

.from_template(template) ⇒ Object


43
44
45
46
47
48
49
50
# File 'lib/hippo/mailer.rb', line 43

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