laravel-email-relay maintained by elitetools
laravel-email-relay
Custom Laravel email transport that forwards mail via an HTTP relay API.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
Installation
1. Install the package:
composer require elitetools/laravel-email-relay
That's it! The package automatically registers the emailrelay mailer and its service configuration via Laravel's package discovery.
Configuration
Just set these variables in your .env file:
MAIL_MAILER=emailrelay
EMAIL_RELAY_URL=https://your-relay-api.example.com
EMAIL_RELAY_TOKEN=your-secret-token
Usage
Use it like any standard Laravel Mailable. Optionally set the X-Email-Type header to categorize the email on the relay side:
Mail::to($user)->send(
(new WelcomeMail($user))->withSymfonyMessage(function ($message) {
$message->getHeaders()->addTextHeader('X-Email-Type', 'Welcome');
})
);
How it works
- Intercepts outgoing mail via a custom Symfony
AbstractTransport - Builds a JSON payload with
type,sendToAddress,senderName,senderAddress,subject, andbody - POSTs to
{EMAIL_RELAY_URL}/sendwith a Bearer token - Throws an exception if the relay returns a non-2xx response
License
MIT