# 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

- A MailBlastr [API key](https://www.mailblastr.com/docs/api-keys/overview).
- A [verified domain](https://www.mailblastr.com/docs/domains/managing) to send from.

## 1. Set your API key

**.env**

```sh
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 2. Send email using HTML

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

**index.rb**

```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"]
```

> **Note:** In a Rails or Sinatra app, issue this request from a controller/route — the JSON body is identical. See [Send an email](https://www.mailblastr.com/docs/api/emails-send) for all fields.
