Quick setup examples

Ruby

Send your first email from Ruby using Net::HTTP against the MailBlastr API.

This guide sends email by POSTing JSON to https://www.mailblastr.com/api/emails using the standard-library net/http, so there is nothing to install. Want the official gem instead? Send emails with Ruby installs mailblastr and calls Mailblastr::Emails.send.

Prerequisites

  • A MailBlastr API key.
  • A verified domain to send from.
  • Ruby 2.7 or newer if you install the official mailblastr gem (that is the gemspec floor). The net/http example below runs on any supported Ruby.

1. Set your API key

.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx

2. Send email using HTML

The easiest way to send an email is with the html field.

index.rb
require "net/http"
require "json"
require "uri"

uri = URI("https://www.mailblastr.com/api/emails")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('MAILBLASTR_API_KEY')}"
request["Content-Type"] = "application/json"
# Required: the API answers a missing User-Agent with 403 validation_error.
request["User-Agent"] = "acme-app/1.0"
request.body = {
  from: "Acme <onboarding@yourdomain.com>",
  to: ["delivered@mailblastr.dev"],
  subject: "hello world",
  html: "<strong>it works!</strong>",
}.to_json

response = http.request(request)
puts JSON.parse(response.body)["id"]
In a Rails or Sinatra app, issue this request from a controller/route — the JSON body is identical. See Send an email for all fields.