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.



24
25
26
# File 'lib/mailblastr/emails.rb', line 24

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



69
70
71
# File 'lib/mailblastr/emails.rb', line 69

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



48
49
50
# File 'lib/mailblastr/emails.rb', line 48

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



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

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



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

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



53
54
55
# File 'lib/mailblastr/emails.rb', line 53

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: "..." })

Write ordinary links. Anchors, markdown links and bare URLs/domains in BOTH the :html and :text bodies are converted to tracked redirects at send time (when the sending domain has click tracking on), so a click is recorded whichever alternative the recipient's mail client renders. Opt-out links are never wrapped, and the content you send is stored and returned UNCHANGED — only the delivered copy carries the tracking URL. Pass { idempotency_key: "order-123" } as the second argument to retry safely.



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

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



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

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" })



64
65
66
# File 'lib/mailblastr/emails.rb', line 64

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