← Back to blog

Symfony Transactional Email API (2026): A Messenger Handler That Posts to /emails

Send transactional email from Symfony with Rovela’s HTTP API: a small HttpClient service, a Messenger handler, environment configuration for the Bearer key, and Idempotency-Key. Not a Laravel tutorial and not a PHP language tour.

Updated November 10, 2026
Symfony Transactional Email API (2026): A Messenger Handler That Posts to /emails

Symfony already speaks HTTP; transactional email should too

A Symfony app already posts JSON to payment providers, dispatches Messenger messages, and keeps secrets in environment variables. The natural way to send transactional email — an invoice that is ready, a “your export can be downloaded” note, a shipping update, a security alert — is the same pattern: one HTTPS POST with a Bearer key, not an SMTP transport hidden behind Symfony Mailer.

Rovela’s Email API is built for that. There is no official SDK and no Symfony bundle you have to pin. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).

This is not a Laravel tutorial, and it is not a PHP language-tour rewrite. If you are on Laravel, use the existing Laravel transactional email API guide. If you have no framework, the vanilla PHP transactional email API post and the send email in PHP tour are already published. This article is everyday Symfony app mail: a small HttpClient service, a Messenger handler, environment variables for the key, an Idempotency-Key on anything a retry might repeat, and documented error handling around the {statusCode, name, message} envelope.

If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Symfony worker belongs on POST /emails.

A Symfony Messenger handler calls an HttpClient emails service that posts JSON to the email API and receives a message id

What you need before the first Symfony send

The first-email guide and the Quick Start are the same five steps, whether your caller is curl or Symfony’s HttpClient:

  1. Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
  2. Add and verify a sending domain (a subdomain such as mail.example.com is a common choice). You cannot send from a domain you have not verified; an unverified or foreign from is refused with a 400 that names the domain. See the domain setup guide and what domain email is.
  3. Create an API key. A sending_access key can send and nothing else — the right default for production. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once.
  4. Send with POST /emails.
  5. Confirm delivery in the dashboard, with GET /emails/:id or GET /emails/:id/events (those reads need full_access or a dashboard session), or with a webhook.

from is a string in the documented form "Acme <hello@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide.

At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part (HTML email API).

An HttpClient service in your src tree

Keep the key on the server. Never put a Rovela key in a Twig template, a Stimulus controller, or a public repository. A leaked sending_access key can send mail as your domain. Symfony’s environment bindings (or $_SERVER values populated from .env.local) are the right place.

This service uses the framework HttpClient, so you stay inside the component you already have for other APIs. The JSON body and headers are identical to the ones in the Emails API.

// src/Email/EmailsClient.php
namespace App\Email;

use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;

class ApiError extends \RuntimeException
{
    public function __construct(
        public readonly int $statusCode,
        public readonly string $errorName,
        string $message
    ) {
        parent::__construct($message !== '' ? $message : "Rovela: HTTP {$statusCode}");
    }
}

final class EmailsClient
{
    public function __construct(
        private HttpClientInterface $httpClient,
        private string $apiKey,
        private string $from,
        private string $baseUrl = 'https://api.rovela.dev',
    ) {}

    public function send(
        string $to,
        string $subject,
        string $html,
        string $text,
        ?string $replyTo = null,
        mixed $tags = null,
        ?string $idempotencyKey = null,
    ): array {
        $headers = [
            'Authorization' => 'Bearer '.$this->apiKey,
            'Content-Type' => 'application/json',
        ];
        if ($idempotencyKey) {
            $headers['Idempotency-Key'] = $idempotencyKey;
        }

        $body = [
            'from' => $this->from,
            'to' => $to,
            'subject' => $subject,
            'html' => $html,
            'text' => $text,
        ];
        if ($replyTo) {
            $body['reply_to'] = $replyTo;
        }
        if ($tags !== null) {
            $body['tags'] = $tags;
        }

        try {
            $response = $this->httpClient->request('POST', $this->baseUrl.'/emails', [
                'headers' => $headers,
                'json' => $body,
                'timeout' => 15,
            ]);
            return $response->toArray();
        } catch (HttpExceptionInterface $e) {
            $payload = $e->getResponse()->toArray(false);
            throw new ApiError(
                (int) ($payload['statusCode'] ?? $e->getResponse()->getStatusCode()),
                (string) ($payload['name'] ?? 'ApiError'),
                (string) ($payload['message'] ?? ''),
            );
        }
    }
}

Bind ROVELA_API_KEY and ROVELA_FROM in services configuration. The from value is the full documented string, including the display name if you use one.

Send an Idempotency-Key header (up to 256 characters) on anything Messenger, a webhook-driven command, or a retried HTTP call might repeat. A retry of the same request within 24 hours returns the original response instead of sending again (Idempotency-Key). For an invoice that became ready once, a key such as invoice-ready:{invoiceId} is enough.

Optional fields you will actually use: Email API tags come back with the message; reply-to is where replies should go; cc and bcc count as recipients for billing and for the 50-recipient cap. How to exercise the service without a sandbox is in how to test a transactional email API.

A Messenger handler that sends after a domain event

Do not call the Emails API from the HTTP request that finalizes an invoice if that request also has other work to finish. Dispatch a message, and let a handler send the mail. The handler below records the message id and returns; it does not wait for the inbox.

// src/Email/SendInvoiceReadyHandler.php
namespace App\Email;

use App\Invoice\InvoiceReady;

final class SendInvoiceReadyHandler
{
    public function __construct(private EmailsClient $emails) {}

    public function __invoke(InvoiceReady $event): void
    {
        $this->emails->send(
            to: $event->customerEmail,
            subject: 'Your invoice is ready',
            html: '<p>Invoice '.$event->number.' can be downloaded from your account.</p>',
            text: 'Invoice '.$event->number.' can be downloaded from your account.',
            tags: ['purpose' => 'invoice-ready', 'invoice_id' => $event->id],
            idempotencyKey: 'invoice-ready:'.$event->id,
        );
    }
}

If a worker retries the handler, the same idempotency key keeps the customer from receiving two invoices that disagree. Configure Messenger to retry on transport failures; do not invent a second send path “just in case.”

If you later need many personalized messages in one go, use batch (POST /emails/batch, up to 100 messages, each processed independently). template and topic_id are rejected on batch rather than ignored; send those through POST /emails.

Errors you should handle in the service

Every documented error uses the same envelope, so one ApiError covers them (Quick Start, Email API error handling):

{ "statusCode": 400, "name": "Bad Request", "message": "html or text body is required" }

The message says what was wrong. Surface it in your own logs as-is.

  • 400 — a missing required field, a base64 attachment that does not decode, a from domain that does not belong to your organization, a template that does not exist, or more than 50 recipients on one message.
  • 401 — missing or invalid credential, or a sending_access key used to read, reschedule, or cancel a message.
  • 429 — rate limit exceeded. Check Retry-After when it is present. A monthly quota error is also returned as 429; retrying will not create capacity.

HTTP 200 on send is not delivery. If you need to look a message up later, GET /emails/:id and GET /emails/:id/events require a full_access key or a dashboard session — do not inject that key into the same service every Messenger worker uses to send. Managing sending domains is a different API and a different key scope (Domains API, Email API authentication, sending domains API).

Delivery is asynchronous — do not poll from the worker

The handler should record the message id and finish. Confirm delivery in the dashboard, with the Email delivery status API, or with a webhook. For production, prefer a webhook over polling GET /emails/:id inside the handler.

A webhook endpoint in Symfony is a controller that reads the raw request body, verifies x-resend-signature, and returns 2xx quickly. Verification is byte-exact HMAC-SHA256 over "<timestamp>.<raw body>" (webhook security). A 400 you return because a payload surprised you is a permanent loss; store anything you do not yet understand rather than rejecting it. Deduplicate on the event id.

When you need a message to go out later, use scheduled_at (scheduled email). When you need many sends in one request, use batch transactional email. Reusable layouts belong in the Templates API and the templates guide.

Symfony Mailer over mailbox SMTP is send-as-self and capped; Symfony app volume belongs on POST /emails

What not to do in a Symfony codebase

Do not configure Symfony Mailer, SwiftMailer leftovers, or a DSN pointed at Rovela mailbox SMTP and call that your application mailer. Mailbox SMTP is for mail apps: a mailbox can send only as itself, and a single client address is limited to 30 messages a minute. That is the wrong default for app volume, which is the point of Email API vs SMTP relay as well.

Do not put a Rovela key in front-end assets or in a repository-committed .env. Call the API from a service and, for anything that can be retried, from a Messenger handler. Authentication is explicit: a key with sending_access in the wrong hands is someone sending mail as your domain.

Do not treat this guide as a Laravel port. Laravel’s mailer, queues, and HTTP facade are a different shape; they already have their own post. Vanilla PHP’s cURL helper is also a different post. This service is for a Symfony container.

Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your Messenger worker should not share a device credential with someone else’s Outlook profile.

If you send on behalf of several customers from one organization, restrict a key to a single domain so a leak cannot send as somebody else (Email API for multi-tenant SaaS). Retries of a failed HTTP call should reuse the same idempotency key (Email API retries).

Wire the service in your container so the HttpClient, the key, and the from string are injected once. A scoped client with a base URI of https://api.rovela.dev is convenient, but it is optional — the service above already names the path /emails. What matters is that controllers stay thin: they dispatch InvoiceReady, and the handler is the only place that calls EmailsClient. That also gives you a seam for tests. You can replace the service in the test container and assert that an invoice-ready event produced one send with the expected idempotency key, without talking to the network. There is still no sandbox and no test key that behaves differently from a live one, so tests that must not send real mail should not call the live API at all.

A compact Symfony checklist

  • Verify the sending domain before you set from. An unverified domain is a 400, not a silent drop.
  • Keep ROVELA_API_KEY in environment configuration and inject it only into server-side services.
  • Prefer a sending_access key in production workers; keep full_access for tooling that reads events or manages webhooks.
  • Send both html and text when you can, and set an Idempotency-Key on any Messenger path a retry can hit twice.
  • Record the message id and return from the handler. Watch delivery with a webhook, not a loop in the worker.
  • If you need a first request in curl, use the transactional email API overview, the curl sending guide, or the HTTP email API explainer — then come back to this service for the Symfony shape.