Send product email from Ruby. Keep callbacks out of the way.
Send transactional email and publish lifecycle events from Ruby services and background jobs with the Send & Retain API.
✓Put the HTTP call in a service object and retries in Active Job or Sidekiq.
One request, complete trace
Request
POST /api/v1/emails
Authorization: Bearer aem_…
Idempotency-Key: welcome-8f21
{ "to": "[email protected]", "template": "welcome" }
202 Accepted
{ "id": "msg_7ca31", "status": "queued" }
[ 01 / 04 ]Client contract
Make email an explicit service, not a hidden callback.
Use the client you already know
Call the stable HTTP API with Net::HTTP, Faraday, or the HTTP library already in your service.
Send typed payloads
Keyword arguments for sender, recipients, template, and props, with symbol keys throughout.
Handle delivery events
Use request.raw_post for signature verification and skip forgery protection on that route only.
[ 02 / 04 ]Server quickstart
Queue one email from Ruby.
The credential never leaves your server. The ID follows the message.
Put the request in a service or background job rather than a model callback.
request = Net::HTTP::Post.new(URI(EMAIL_URL))
request['Authorization'] = "Bearer #{ENV.fetch('AEM_KEY')}"
request['Idempotency-Key'] = "welcome-#{user.id}"
request['Content-Type'] = 'application/json'
request.body = { to: user.email, template: 'welcome' }.to_jsonAccepted response
{ "id": "msg_7ca31", "status": "queued" }[ 03 / 04 ]Quickstart
Give each send an obvious owner and retry path.
Wrap the API in a service object
Centralize the key, timeout, error handling, and idempotency convention.
Enqueue after commit
Send from Active Job or Sidekiq after the application record has been committed.
Return evidence to the job
Store the accepted message ID so retries and support checks refer to the same send.
Production checklist
- Secrets stay server-side
- Timeout and retry policy
- Idempotent webhook handler
- Structured error logging
[ 04 / 04 ]Related
Use Ruby in context
Questions people ask us
Queue your first Ruby email.
Call from a service or job, then keep the returned ID for the delivery trace.