How to send emails with Elixir / Phoenix
Send emails from Elixir/Phoenix with the `Req` library.
There is no official SDK — call the Publiq REST API with your language HTTP client, from the server, with the API key in the Authorization header.
defmodule MyApp.Publiq do
def send_welcome(email) do
Req.post!("https://api.publiq.digital/v1/emails",
headers: [{"authorization", "Bearer #{System.get_env("PUBLIQ_API_KEY")}"}],
json: %{
from: "you@yourdomain.com",
to: email,
templateKey: "welcome-email",
variables: %{first_name: "Ana"}
}
)
end
endBest practices
- Always call Publiq from the server — never expose the API key on the client.
- Create the client instance once and reuse it across requests.
- Prefer
templateKeyover inline HTML to keep content versioned. - Handle
PubliqError(status/code); the SDK already retries transient errors with backoff. - Send from a verified domain — see Domains.