13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/mailerooby/email_sender.rb', line 13
def self.send_email(from:, to:, subject:, body:, cc: nil, bcc: nil, reply_to: nil, attachments: nil)
validate_parameters(from: from, to: to, subject: subject, body: body)
= {
'X-API-Key' => Mailerooby.sending_api_key
}
body = { from: from, to: to, subject: subject, body: body, cc: cc, bcc: bcc, reply_to: reply_to, attachments: attachments }
response = post(base_uri, headers: , body: body, multipart: true)
case response.code
when 400
raise BadRequestError, "Bad request: #{response.body}"
when 401
raise UnauthorizedError, "Unauthorized: #{response.body}"
when 200
JSON.parse(response.body)
else
raise GeneralAPIError, "API Error: #{response.body}"
end
end
|