Frameworks
Ruby on Rails
Send transactional emails from Rails with one Net::HTTP.post — no SDK.
Send transactional emails from your Rails app. No SDK required — one
Net::HTTP.post is the whole integration.
1. Set up credentials
EDITOR="code --wait" rails credentials:editAdd:
emitd:
api_key: esk_live_...2. Create an email service
require 'net/http'
require 'json'
module Emitd
API = URI('https://api.emitd.com/v1/email')
def self.send_email(payload)
Net::HTTP.post(
API,
payload.to_json,
'Authorization' => "Bearer #{Rails.application.credentials.emitd[:api_key]}",
'Content-Type' => 'application/json'
)
end
end3. Send from a job
class WelcomeEmailJob < ApplicationJob
queue_as :default
def perform(user)
Emitd.send_email(
from: 'hello@yourdomain.com',
to: [user.email],
subject: "Welcome, #{user.name}!",
html_body: ApplicationController.render(
template: 'welcome_mailer/welcome',
assigns: { user: user },
layout: false
),
tags: { 'campaign' => 'welcome', 'user_id' => user.id.to_s }
)
end
endActiveJob gives you retries for free — pair them with an
Idempotency-Key (e.g. "welcome:#{user.id}") so a
retried job can't double-send.
4. The template
<h1>Welcome, <%= @user.name %>!</h1>
<p>Thanks for signing up for our service.</p>
<p>We're excited to have you on board.</p>Render it inline as above, or move content to
emitd templates and send with
template_alias instead.
5. Use it in a controller
class RegistrationsController < ApplicationController
def create
@user = User.new(user_params)
if @user.save
WelcomeEmailJob.perform_later(@user)
redirect_to root_path, notice: 'Welcome!'
end
end
end6. Test with sandbox recipients
Emitd.send_email(
from: 'hello@yourdomain.com',
to: ['delivered@relay.dev'],
subject: 'Test',
html_body: '<p>Test email</p>',
test_mode: true
)bounced@relay.dev and complained@relay.dev simulate the other outcomes;
inspect results at GET /v1/email/test-events. See
Test mode.