Class: Sevk::Resources::Emails

Inherits:
Base
  • Object
show all
Defined in:
lib/sevk/resources/emails.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Sevk::Resources::Base

Instance Method Details

#get(id) ⇒ Hash

Get an email by ID

Parameters:

  • id (String) —

    Email ID

Returns:

  • (Hash) —

    Email details



50
51
52
# File 'lib/sevk/resources/emails.rb', line 50

def get(id)
  client.get("/emails/#{id}")
end

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

Send an email with optional attachments

Parameters:

  • to (String, Array<String>) —

    Recipient email(s)

  • subject (String) —

    Email subject

  • html (String) —

    HTML content

  • from (String) —

    Sender email

  • from_name (String, nil) (defaults to: nil) —

    Sender name

  • reply_to (String, nil) (defaults to: nil) —

    Reply-to address

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

    Plain text content

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

    Custom headers

  • tags (Array, nil) (defaults to: nil) —

    Tags

  • attachments (Array<Hash>, nil) (defaults to: nil) —

    Attachments (max 10, 10MB total) Each attachment: { filename: String, content: String (base64), content_type: String }

Returns:

  • (Hash) —

    Response with :id or :ids



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

def send(to:, subject:, html:, from:, from_name: nil, reply_to: nil, text: nil, headers: nil, tags: nil, attachments: nil)
  body = {
    to: to,
    subject: subject,
    html: html,
    from: from
  }
  body[:fromName] = from_name if from_name
  body[:replyTo] = reply_to if reply_to
  body[:text] = text if text
  body[:headers] = headers if headers
  body[:tags] = tags if tags
  body[:attachments] = attachments if attachments
  client.post("emails", body)
end

#send_bulk(emails) ⇒ Hash

Send multiple emails in bulk

Parameters:

  • emails (Array<Hash>) —

    Array of email parameter hashes (max 100)

Returns:

  • (Hash) —

    Response with :success, :failed, :ids, :errors



42
43
44
# File 'lib/sevk/resources/emails.rb', line 42

def send_bulk(emails)
  client.post("emails/bulk", { emails: emails })
end