Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/postmark/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,43 @@ def deliver_in_batches_with_templates(message_hashes)
end
end

# --- Bulk Email (Early Access) -----------------------------------------
# See: https://postmarkapp.com/developer/api/bulk-email
#
# Sends a bulk email request where the content is defined once, and
# per-recipient data is provided via the `Messages` array. The expected
# payload matches Postmark's Bulk API body. Example shape:
# {
# From: "sender@example.com",
# Subject: "Hello {{FirstName}}",
# HtmlBody: "<b>Hi, {{FirstName}}</b>",
# TextBody: "Hi, {{FirstName}}",
# MessageStream: "broadcast",
# Messages: [
# { To: "a@example.com", TemplateModel: { FirstName: "Ada" } },
# { To: "b@example.com", TemplateModel: { FirstName: "Bob" } }
# ]
# }
#
# Returns a hash with keys like :id, :status, :submitted_at.
def deliver_bulk(attributes = {})
data = serialize(HashHelper.to_postmark(attributes, :deep => true))

with_retries do
format_response http_client.post('email/bulk', data), :deep => true
end
end

# Fetch the status/details of a bulk request by its ID returned from
# `deliver_bulk`.
# Returns a hash with keys like :id, :status, :submitted_at,
# :total_messages, :percentage_completed, :subject
def get_bulk_status(bulk_request_id)
with_retries do
format_response http_client.get("email/bulk/#{bulk_request_id}"), :deep => true
end
end

def get_stats_totals(options = {})
format_response(http_client.get('stats/outbound', options))
end
Expand Down