Class: Eco::API::Common::Session::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/common/session/mailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(enviro:) ⇒ Mailer



11
12
13
14
# File 'lib/eco/api/common/session/mailer.rb', line 11

def initialize (enviro:)
  raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
  @enviro = enviro
end

Instance Method Details

#mail(to: nil, subject:, body:) ⇒ Object

Sends an email



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/eco/api/common/session/mailer.rb', line 20

def mail(to: nil, subject:, body:)
  ses.send_email(
    destination: {
      to_addresses: [fetch_to(to)].flatten,
    },
    source:  fetch_from,
    message: {
      subject: {
        charset: "UTF-8",
        data: subject,
      },
      body: {
        # NOTE - html: will let you send html instead
        # you can use both at once if you like
        text: {
          charset: "UTF-8",
          data: body
        }
      }
    }
  ).tap do |response|
    logger.debug("Sent email to #{to} (MessageId: #{response.message_id})")
  end
end