Class: OfficeBoy::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/office_boy/mail.rb

Class Method Summary collapse

Class Method Details

.deliver(template:, attributes:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/office_boy/mail.rb', line 3

def self.deliver(template:, attributes:)
  raise Errors::NotDefiniedEmailTemplate unless OfficeBoy.configuration.templates.key?(template)

  response = OfficeBoy::Request.call(
    method_name: :post,
    path: 'mail/send',
    payload: {
      from: {
        email: attributes[:from_email],
        name: attributes[:from_name]
      },
      template_id: OfficeBoy.configuration.templates[template],
      personalizations: [
        {
          to: [{
            email: attributes[:to_email],
            name: attributes[:to_name]
          }],
          subject: attributes[:subject]
        }
      ],
      headers: attributes[:substitutions]
    }
  )

  response.code == 202
end