Skip to content

Send Emails with Elixir

Learn how to send transactional emails using PostStack and Elixir.

1. Install the SDK

bash
# mix.exs
{:req, "~> 0.5"}

2. Initialize the client

elixir
# config/config.exs
config :my_app,
  poststack_api_key: System.get_env("POSTSTACK_API_KEY")

3. Send an email

elixir
defmodule MyApp.Email do
  @base_url "https://api.poststack.dev"

  def send_welcome(to) do
    api_key = Application.get_env(:my_app, :poststack_api_key)

    Req.post!("#{@base_url}/v1/emails",
      json: %{
        from: "hello@yourdomain.com",
        to: to,
        subject: "Hello from Elixir!",
        html: "<h1>Welcome!</h1>"
      },
      headers: [
        {"authorization", "Bearer #{api_key}"},
        {"content-type", "application/json"}
      ]
    )
  end
end

Notes

  • Uses the Req HTTP client library

Ready to send emails with Elixir?

Create a free account and get your API key in under a minute.