mailway / mailway-mailer
Mailway transport for Symfony Mailer and Laravel: send through Mailway's HTTP API or SMTP relay, and verify Mailway's signed webhooks.
Package info
github.com/mailway/mailway-mailer
Type:symfony-bundle
pkg:composer/mailway/mailway-mailer
Requires
- php: >=8.2
- psr/clock: ^1.0
- symfony/http-client: ^6.4.51|^7.4.24|^8.1.12
- symfony/mailer: ^6.4.51|^7.4.24|^8.1.12
- symfony/mime: ^6.4|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- orchestra/testbench: ^9.0|^10.0|^11.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^11.5|^12.0
- symfony/clock: ^6.4|^7.0|^8.0
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/http-foundation: ^6.4|^7.0|^8.0
- symfony/webhook: ^6.4|^7.0|^8.0
Suggests
- symfony/webhook: To receive Mailway's signed webhooks as Symfony RemoteEvents.
Provides
None
Conflicts
- symfony/framework-bundle: <6.4
- symfony/http-foundation: <6.4
- symfony/webhook: <6.4
Replaces
None
This package is not auto-updated.
Last update: 2026-11-30 23:33:40 UTC
README
Mailway Mailer
Mailway transport for Symfony Mailer and Laravel.
Mailway sits between your app and the email providers you already use. It keeps every email as it received it and shows what happened to each one, and if a provider refuses a mail, it sends it through the next.
mailway://: sends the message your app built, as it built it, over Mailway's HTTP API.mailway+smtp://: the same, over Mailway's SMTP relay.- Webhooks: verifies Mailway's signed webhook deliveries and turns them into Symfony Remote Events (a mailer event where Symfony has one).
composer require mailway/mailway-mailer -W
-W lets Composer update Symfony Mailer and HttpClient to their patched releases if your app is locked to older ones.
Requires PHP 8.2 or later, and Symfony Mailer and HttpClient 6.4 (6.4.51 or later), 7.4 (7.4.24 or later), or 8.1.12 or later. Earlier releases have known security issues. Two of them (CVE-2026-133751, CVE-2026-133755) are in the STARTTLS upgrade that mailway+smtp relies on with Symfony Mailer 7.4 and 8. The Laravel integration needs Laravel 11 or later.
In a Symfony application, Symfony Flex enables the package's bundle when you install it. In Laravel, the service provider is discovered automatically. So setting the DSN or the mailer is all the setup there is.
Other frameworks built on Symfony Mailer, such as Drupal or Craft CMS, can use the transport if they register its factory (Mailway\Mailer\Transport\MailwayTransportFactory). This package doesn't do that for them, and it isn't tested with them.
How your mail is sent
Mailway sends the message your app built, as it built it: its own Message-ID, MIME structure and DKIM signature reach your provider, apart from a few documented changes, such as removing the Bcc field. Mailway keeps a copy of each message as it received it.
It sends through your provider's SMTP server, or through the raw-message API of Amazon SES or Mailgun. Most provider accounts can already do this with the credentials you gave Mailway: their API key also works over SMTP, or their API takes a raw message. Brevo, MailerSend, and SMTP2GO need their own SMTP username and password, which you add to the account in the Mailway console. An account set to Send via: API only can't, unless it is Amazon SES or Mailgun. If none of the project's provider accounts can carry the message, Mailway answers 422 (no_raw_mime_provider) and the transport throws an HttpTransportException with Mailway's message, which says how to fix it.
The mail ID Mailway gives each mail (m.…) becomes the sent message's getMessageId(), which webhook events carry too.
Symfony
# .env MAILER_DSN=mailway://${MAILWAY_API_KEY}@default
# .env.local MAILWAY_API_KEY=mw_live_...
Symfony commits .env to git, so put the key in .env.local or the server's environment.
That is the whole setup: Symfony Flex adds Mailway\Mailer\MailwayMailerBundle to config/bundles.php, and the bundle registers the transport factory, as FrameworkBundle does for Symfony's own bridges. Without Flex, add that line to config/bundles.php yourself:
Mailway\Mailer\MailwayMailerBundle::class => ['all' => true],
Check the setup with Symfony's own command: php bin/console mailer:test you@example.com.
default picks Mailway's production host. A mw_test_… API key sends to the sandbox (api.mailway.dev) automatically. There, Mailway keeps each mail as Captured and sends nothing to a provider unless you release it.
To send over Mailway's SMTP relay instead, with an SMTP credential:
MAILER_DSN=mailway+smtp://SMTP_USERNAME:SMTP_PASSWORD@default
SMTP takes longer: a send is a series of round trips (connect, TLS, login, envelope, message) where HTTPS makes one request. Timed from a PHP app about 25 ms from Mailway, the median wait until Mailway received a small mail was 134 ms over mailway:// and 446 ms over mailway+smtp:// (port 465) with a new connection per mail, and 66 ms against 132 ms on one connection reused for many mails.
For the SMTP sandbox, name the host: mailway+smtp://SMTP_USERNAME:SMTP_PASSWORD@smtp.mailway.dev. Port 465 (the default) and its alternate 2465 use TLS from the first byte. Every other Mailway port, such as …@default:587, upgrades with STARTTLS. On Symfony Mailer 7.4 and 8 the transport requires the upgrade, so it never sends your password over a connection that wasn't upgraded. Symfony Mailer 6.4 can't require it, so keep the default port 465 there.
Laravel
MAIL_MAILER=mailway MAILWAY_API_KEY=mw_live_...
That is the whole setup. The service provider is discovered automatically, and it adds a mailway mailer and services.mailway.key (from MAILWAY_API_KEY) to your configuration. Anything you set yourself in config/mail.php or config/services.php wins, and php artisan config:cache keeps it all.
The mailer sends each message as Laravel built it, as mailway:// does. To send over Mailway's SMTP relay instead, give the mailer a DSN in config/mail.php:
'mailers' => [ 'mailway' => [ 'transport' => 'mailway', 'dsn' => 'mailway+smtp://'.env('MAILWAY_SMTP_USERNAME').':'.env('MAILWAY_SMTP_PASSWORD').'@default', ], // ... ],
Laravel's tag() and metadata() on a mailable become Mailway tags and metadata. On mailway+smtp they stay ordinary X-Tag and X-Metadata-… headers.
Mailway options
On mailway://, these headers set Mailway's send options. The transport reads them and removes them from the message, so they never reach a recipient. If you sign the message with DKIM before sending it, leave these headers out of the signature (the headers_to_ignore option of Symfony's DkimSigner); a signature that covers one is refused with an exception, because removing the header would break it.
| Header | Becomes | Example |
|---|---|---|
X-Mailway-Category |
category |
Password reset |
X-Mailway-Idempotency-Key |
the Idempotency-Key request header (12–40 characters of letters, digits, -, and _): a retry with the same key is not sent twice |
order-84412-receipt |
X-Mailway-Scheduled-At |
scheduled_at: a date and time at most 72 hours ahead, as an RFC 3339 date-time with a UTC offset or Z (a date header works too; a relative value such as +1 hour is refused). Scheduled sends aren't on every plan. On a plan without them the API answers 402 (scheduling_unavailable), see Plans & add-ons |
2026-11-02T09:00:00Z |
X-Mailway-Paused |
paused: hold the mail until it's released in the console |
true |
X-Mailway-Provider |
routing.provider: a provider family, or a comma-separated list in order of preference. The project needs a provider account of that family attached |
amazon-ses, postmark |
X-Mailway-Strategy |
routing.strategy |
fallback |
Symfony TagHeader |
tags |
password-reset |
Symfony MetadataHeader |
metadata |
order_id: 84412 |
An X-Mailway-… header not in this table is refused with an exception. The send endpoint reference has the limits for each field.
If your app retries failed sends (Symfony Messenger and Laravel queues both do), set X-Mailway-Idempotency-Key. Otherwise, a mail whose request timed out after Mailway received it is sent a second time when your app retries.
Symfony:
use Mailway\Mailer\Transport\MailwayApiTransport; use Symfony\Component\Mailer\Header\MetadataHeader; use Symfony\Component\Mailer\Header\TagHeader; $email->getHeaders() ->addTextHeader(MailwayApiTransport::HEADER_CATEGORY, 'Password reset') ->addTextHeader(MailwayApiTransport::HEADER_IDEMPOTENCY_KEY, 'password-reset-'.$token->id) ->add(new TagHeader('password-reset')) ->add(new MetadataHeader('user_id', (string) $user->id));
Laravel:
public function headers(): Headers { return new Headers(text: ['X-Mailway-Category' => 'Password reset']); } public function envelope(): Envelope { return new Envelope(subject: 'Reset your password', tags: ['password-reset'], metadata: ['user_id' => $this->user->id]); }
Mailway's SMTP relay doesn't read these headers, so mailway+smtp refuses a message that carries one, instead of sending a paused or scheduled mail at once. This also applies when mailway+smtp is the second mailer in a Laravel failover setup: a mail with an X-Mailway-… header fails there instead of falling back.
Sending fields instead
mailway+api://MAILWAY_API_KEY@default sends the message as fields (from, to, subject, html, text, attachments, headers) to POST /v1/send, and Mailway builds the message again. You won't normally need it: it remains for apps set up with version 1.0, whose Laravel mailer used it. It takes the same options, and it refuses what fields can't carry: a custom Message-ID, Date or Return-Path (Laravel's mail.return_path), MIME structure headers (Content-Type, MIME-Version, …), and a header that appears twice. mailway+https:// is another name for mailway://.
Webhooks
Each Mailway webhook endpoint has a signing secret (whsec_…). The console shows it once, when you create the endpoint under Webhooks. If you lose it, rotate it there.
Symfony
Install Symfony's Webhook component first: composer require symfony/webhook. The bundle registers the parser only when it is installed.
# config/packages/webhook.yaml framework: webhook: routing: mailway: service: mailer.webhook.request_parser.mailway secret: '%env(MAILWAY_WEBHOOK_SECRET)%'
The bundle registers the parser under that name, as FrameworkBundle names the parsers of Symfony's own bridges (mailer.webhook.request_parser.postmark, …).
Point the endpoint at https://yourapp.com/webhook/mailway and consume the events:
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer; use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface; use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent; use Symfony\Component\RemoteEvent\RemoteEvent; #[AsRemoteEventConsumer('mailway')] final class MailwayEventConsumer implements ConsumerInterface { public function consume(RemoteEvent $event): void { if ($event instanceof MailerDeliveryEvent && MailerDeliveryEvent::BOUNCE === $event->getName()) { // $event->getId() is the Mailway mail ID (m.…), the one getMessageId() returned after sending. // getRecipientEmail() is the first address the provider's report names, or the first To address. // A report can name several: read $event->getPayload()['data']['recipients'] for all of them. // $event->getReason(), $event->getMetadata(), $event->getPayload() ... } } }
The event names predate Mailway's state names: mail.accepted means Mailway received the mail, and mail.sent means a provider accepted it.
| Mailway event | Means | Symfony event |
|---|---|---|
mail.accepted |
Mailway received the mail from your app | MailerDeliveryEvent::RECEIVED |
mail.sent |
a provider accepted the mail | a plain RemoteEvent named mail.sent (Symfony has no matching event) |
mail.delivered |
the provider's delivery event confirmed it | MailerDeliveryEvent::DELIVERED |
mail.bounced |
a recipient's server refused it, permanently or for now | MailerDeliveryEvent::BOUNCE, or DEFERRED when it bounced for now (data.bounce is transient) |
mail.delayed |
the provider reported a delay and is still trying | MailerDeliveryEvent::DEFERRED |
mail.failed |
rejected (by a rule, a person, …), or every attempt failed | MailerDeliveryEvent::DROPPED, with Mailway's reason (rule, exhausted, …) |
mail.suppressed |
the project's suppression list blocked it | MailerDeliveryEvent::DROPPED, reason suppressed |
mail.complained |
the recipient marked it as spam | MailerEngagementEvent::SPAM |
webhook.test, and types added later |
a plain RemoteEvent named after the Mailway type, with the full payload |
Every delivery with a valid signature becomes an event, so the console's Send test succeeds, and an event type added later reaches your consumer instead of failing the request.
Deliveries are at-least-once, so the same event can arrive more than once. Deduplicate on the payload's data.event_id ($event->getPayload()['data']['event_id']), which is the same on every delivery of one event. Not on the name and the mail ID: one mail gets several events with the same name, for example a bounce for each recipient. $event->getDate() is when the event happened (data.occurred_at). See Delivery semantics.
Laravel
Set MAILWAY_WEBHOOK_SECRET in .env (it becomes services.mailway.webhook_secret), and route the endpoint through the middleware:
// routes/web.php (exclude the path from CSRF verification) use Mailway\Mailer\Laravel\VerifyMailwaySignature; Route::post('/webhooks/mailway', MailwayWebhookController::class) ->middleware(VerifyMailwaySignature::class);
The middleware answers 403 when the signature doesn't match, or when its timestamp is more than 5 minutes from your server's clock. Mailway retries a refused delivery and turns the endpoint off after 24 hours of failures, so check the secret if deliveries keep failing. Answer a verified request with a 2xx within 10 seconds, and do the work in a queued job.
Anything else
use Mailway\Mailer\Webhook\MailwaySignature; MailwaySignature::verify($rawBody, $request->getHeaderLine('X-Mailway-Signature'), $secret); // throws Mailway\Mailer\Exception\InvalidSignatureException when it doesn't match
Verify the raw request body, before any JSON decoding.
Development
composer install composer test # PHPUnit composer lint # php-cs-fixer (dry run) + PHPStan
The code follows Symfony's coding standard, so it can be proposed upstream as a Symfony Mailer bridge.
Security
Report vulnerabilities to security@mailway.net, not in a public issue. See mailway.net/trust.
License
MIT. See LICENSE.