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.



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

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



17
18
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 17

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|
    msg = "Sent email (MessageId: #{response.message_id}) to #{fetch_destination(to: to, cc: cc, bcc: bcc)}"
    puts msg
    logger.debug(msg)
  end
end