Module: Mailblastr::Emails

Defined in:
lib/mailblastr/emails.rb

Overview

Send and inspect emails. Inbound mail lives under Mailblastr::Emails::Receiving.

Defined Under Namespace

Modules: Receiving

Class Method Summary collapse

Class Method Details

.batch(payloads, options = {}) ⇒ Object

Send up to 100 emails in one request. POST /emails/batch (alias of Batch.send). Batch items reject attachments and scheduled_at — send those individually via Emails.send.



17
18
19
# File 'lib/mailblastr/emails.rb', line 17

def batch(payloads, options = {})
  Client.request(:post, "/emails/batch", body: payloads, options: options)
end

.cancel(email_id) ⇒ Object

Cancel a scheduled email. POST /emails/:id/cancel



62
63
64
# File 'lib/mailblastr/emails.rb', line 62

def cancel(email_id)
  Client.request(:post, "/emails/#{Client.path_escape(email_id)}/cancel")
end

.get(email_id) ⇒ Object

Retrieve a sent email and its events. GET /emails/:id



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

def get(email_id)
  Client.request(:get, "/emails/#{Client.path_escape(email_id)}")
end

.get_attachment(email_id, attachment_id) ⇒ Object

Retrieve one attachment's metadata. GET /emails/:id/attachments/:attachment_id



51
52
53
# File 'lib/mailblastr/emails.rb', line 51

def get_attachment(email_id, attachment_id)
  Client.request(:get, "/emails/#{Client.path_escape(email_id)}/attachments/#{Client.path_escape(attachment_id)}")
end

.list(params = {}) ⇒ Object

List sent emails (trimmed list items) — cursor pagination plus optional server-side filters: campaign_id, automation_id, source ("individual"), domain_id, status (matched case-insensitively against the row's last_event) and search (recipients, subject and sender). q is the server's alias for search, honoured only when search is absent. GET /emails



27
28
29
30
31
32
# File 'lib/mailblastr/emails.rb', line 27

def list(params = {})
  query = Client.pagination(params).merge(
    Client.filters(params, :campaign_id, :automation_id, :source, :domain_id, :status, :search, :q)
  )
  Client.request(:get, "/emails", query: query)
end

.list_attachments(email_id) ⇒ Object

List a sent email's attachments. GET /emails/:id/attachments



46
47
48
# File 'lib/mailblastr/emails.rb', line 46

def list_attachments(email_id)
  Client.request(:get, "/emails/#{Client.path_escape(email_id)}/attachments")
end

.send(params, options = {}) ⇒ Object

Send a single email. POST /emails Mailblastr::Emails.send({ from: "...", to: ["..."], subject: "...", html: "..." }) Pass { idempotency_key: "order-123" } as the second argument to retry safely.



10
11
12
# File 'lib/mailblastr/emails.rb', line 10

def send(params, options = {})
  Client.request(:post, "/emails", body: params, options: options)
end

.sourcesObject

Per-source send metrics, one row per campaign / automation / individual origin. Not paginated. GET /emails/sources



36
37
38
# File 'lib/mailblastr/emails.rb', line 36

def sources
  Client.request(:get, "/emails/sources")
end

.update(email_id, params) ⇒ Object

Reschedule a scheduled email. PATCH /emails/:id Mailblastr::Emails.update("email_id", { scheduled_at: "2026-08-01T09:00:00Z" })



57
58
59
# File 'lib/mailblastr/emails.rb', line 57

def update(email_id, params)
  Client.request(:patch, "/emails/#{Client.path_escape(email_id)}", body: params)
end