uSend Docs
Quickstarts

Send with Rails

Send email from Rails with the usend gem, or through Action Mailer over SMTP.

You need a verified domain and an API key. Use the gem for API features (templates, batches, scheduling, idempotency), or Action Mailer over SMTP so your existing mailers keep working.

Option 1: the Ruby gem

Gemfile
gem "usend"
config/initializers/usend.rb
USEND = Usend::Client.new(api_key: ENV.fetch("USEND_API_KEY"))
app/jobs/welcome_email_job.rb
class WelcomeEmailJob < ApplicationJob
  def perform(user)
    USEND.emails.send_email(
      {
        from: "Acme <[email protected]>",
        to: [user.email],
        subject: "Welcome",
        html: ApplicationController.render(template: "user_mailer/welcome", locals: { user: user })
      },
      idempotency_key: "welcome-#{user.id}"
    )
  end
end
ruby
WelcomeEmailJob.perform_later(user)

The idempotency key makes a retried job safe: usend returns the first result instead of sending again. See Idempotency. A failure raises Usend::Error.

Verify webhooks in a controller with Usend::Webhook.verify(payload: request.raw_post, headers: request.headers.to_h, secret: ENV["USEND_WEBHOOK_SECRET"]) and skip_forgery_protection for that action.

Option 2: Action Mailer over SMTP

config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.usend.et",
  port: 587,
  user_name: "usend",
  password: ENV.fetch("USEND_API_KEY"),
  authentication: :plain,
  enable_starttls_auto: true
}

Your API key is the password; Usend.smtp_settings(api_key: ENV["USEND_API_KEY"], port: 587) returns the same settings. See Send with SMTP.

Without the gem

Net::HTTP works too: POST https://api.usend.et/emails with an Authorization: Bearer header and a JSON body.

Next: Send emails.