Class: Anypost::Resources::Email
- Defined in:
- lib/anypost/resources/email.rb
Overview
Operations on the /email endpoints.
Attachment content is the raw file bytes (e.g. from File.binread); the
SDK base64-encodes it for transport. Do not pre-encode it.
Instance Method Summary collapse
-
#send(email, idempotency_key = nil) ⇒ Object
Send a single message.
-
#send_batch(batch, idempotency_key = nil) ⇒ Object
Send 1-100 independent messages in one request.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Anypost::Resources::Base
Instance Method Details
#send(email, idempotency_key = nil) ⇒ Object
Send a single message.
All addresses in to/cc/bcc share one envelope. Returns the queued
message id; raises an Error subclass on failure.
14 15 16 17 |
# File 'lib/anypost/resources/email.rb', line 14 def send(email, idempotency_key = nil) request_object(:post, "/email", body: (email), idempotent: true, idempotency_key: idempotency_key) end |
#send_batch(batch, idempotency_key = nil) ⇒ Object
Send 1-100 independent messages in one request.
A mixed-outcome batch (HTTP 207) returns normally — inspect each entry's
status in data; it does not raise.
23 24 25 26 27 28 29 |
# File 'lib/anypost/resources/email.rb', line 23 def send_batch(batch, idempotency_key = nil) body = batch.dup body[:defaults] = (batch[:defaults]) if batch[:defaults] body[:emails] = Array(batch[:emails]).map { |email| (email) } request_object(:post, "/email/batch", body: body, idempotent: true, idempotency_key: idempotency_key) end |