# Elixir

> Send your first email from Elixir using Req against the MailBlastr API.

MailBlastr has no Elixir package — you send email by POSTing JSON to `https://api.mailblastr.com/emails`. The example below uses [`Req`](https://hex.pm/packages/req), a batteries-included HTTP client.

## 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. Install an HTTP client

Add `req` to your dependencies in `mix.exs`, then run `mix deps.get`.

**mix.exs**

```elixir
def deps do
  [
    {:req, "~> 0.5"}
  ]
end
```

## 2. Send email using HTML

Read the API key from the environment and POST the email body. The easiest way to send is with the `html` field.

**send.exs**

```elixir
api_key = System.get_env("MAILBLASTR_API_KEY")

response =
  Req.post!("https://api.mailblastr.com/emails",
    auth: {:bearer, api_key},
    json: %{
      from: "Acme <onboarding@yourdomain.com>",
      to: ["delivered@example.com"],
      subject: "hello world",
      html: "<strong>it works!</strong>"
    }
  )

IO.inspect(response.body["id"])
```

> **Note:** In a Phoenix app, send from a controller action with the same body. See [Send an email](https://www.mailblastr.com/docs/api/emails-send) for every supported field.
