Quick setup examples

Ruby

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

MailBlastr has no Ruby gem — you send email by POSTing JSON to https://api.mailblastr.com/emails. The example below uses the standard-library net/http, so there is nothing to install.

Prerequisites

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://api.mailblastr.com/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"
request.body = {
  from: "Acme <onboarding@yourdomain.com>",
  to: ["delivered@example.com"],
  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.