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



55
56
57
# File 'lib/mailblastr/emails.rb', line 55

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



34
35
36
# File 'lib/mailblastr/emails.rb', line 34

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



44
45
46
# File 'lib/mailblastr/emails.rb', line 44

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 campaign_id, automation_id, source ("individual"), and domain_id filters. GET /emails



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

def list(params = {})
  query = Client.pagination(params)
  %i[campaign_id automation_id source domain_id].each do |k|
    v = Client.opt(params, k)
    query[k] = v unless v.nil?
  end
  Client.request(:get, "/emails", query: query)
end

.list_attachments(email_id) ⇒ Object

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



39
40
41
# File 'lib/mailblastr/emails.rb', line 39

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

.update(email_id, params) ⇒ Object

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



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

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