Module: Marfa::Helpers::Email

Defined in:
lib/marfa/helpers/email.rb

Overview

Provide helpers for Sinatra controllers

Instance Method Summary collapse

Instance Method Details

#send_email(options) ⇒ Object

Send email using mailbox config @example:

send_email({ template: 'mail', to: '[email protected]', mailbox: :admin, subject: 'Hello', data: { title: 'Hello!' } })

Parameters:

  • options (Hash)
    • params



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/marfa/helpers/email.rb', line 13

def send_email(options)
  mailbox = options[:mailbox] || :default

  config = Marfa.config.email[mailbox]
  return if config.nil?

  template_engine = Marfa.config.template_engine || :haml
  body = render(template_engine, :"#{options[:template]}", locals: options[:data], layout: false)

  Pony.options = {
    via: :smtp,
    via_options: config
  }

  mail = {
    to: options[:to],
    subject: options[:subject],
    html_body: body
  }

  mail[:from] = config[:from] unless config[:from].nil?

  Pony.mail(mail)
end