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

Returns a new instance of Mailer.



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

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:, cc: nil, bcc: nil) ⇒ Object

Sends an email

Parameters:

  • to (String) (defaults to: nil)

    destination email address

  • subject (String)

    subject of the email

  • body (String)

    html or plain text message



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

def mail(to: nil, subject:, body:, cc: nil, bcc: nil)
  ses.send_email(
    destination: fetch_destination(to: to, cc: cc, bcc: bcc),
    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