Class: UtoboEmail::Emails

Inherits:
Object
  • Object
show all
Defined in:
lib/utobo_email/emails.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Emails

Returns a new instance of Emails.



3
4
5
# File 'lib/utobo_email/emails.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#get(id) ⇒ Hash

Retrieve the status of a previously sent email.

Parameters:

  • id (String)

    The email ID returned by send()

Returns:

  • (Hash)

    { "id", "from", "to", "subject", "status", "ses_message_id", "created_at" }



41
42
43
# File 'lib/utobo_email/emails.rb', line 41

def get(id)
  @client.get("/send-email/#{id}")
end

#send(from:, to:, subject:, html: nil, text: nil, reply_to: nil, cc: nil, bcc: nil, attachments: nil, headers: nil) ⇒ Hash

Send a transactional email.

Parameters:

  • from (String)

    Sender address ("Name " format)

  • to (String, Array<String>)

    Recipient(s)

  • subject (String)

    Email subject

  • html (String, nil) (defaults to: nil)

    HTML body

  • text (String, nil) (defaults to: nil)

    Plain-text body

  • reply_to (String, Array<String>, nil) (defaults to: nil)
  • cc (String, Array<String>, nil) (defaults to: nil)
  • bcc (String, Array<String>, nil) (defaults to: nil)
  • attachments (Array<Hash>, nil) (defaults to: nil)

    Each hash requires :filename and :content (base64), optional :contentType

  • headers (Hash, nil) (defaults to: nil)

    Custom email headers

Returns:

  • (Hash)

    { "id" => "...", "message" => "..." }



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/utobo_email/emails.rb', line 20

def send(from:, to:, subject:, html: nil, text: nil, reply_to: nil, cc: nil, bcc: nil, attachments: nil, headers: nil)
  body = {
    from: from,
    to: Array(to),
    subject: subject,
  }
  body[:html] = html if html
  body[:text] = text if text
  body[:reply_to] = Array(reply_to) if reply_to
  body[:cc] = Array(cc) if cc
  body[:bcc] = Array(bcc) if bcc
  body[:attachments] = attachments if attachments
  body[:headers] = headers if headers

  @client.post("/send-email", body)
end