africoders/laravel-mailer

Custom Laravel mailer that routes emails through an external API

dev-main 2025-05-26 04:35 UTC

This package is auto-updated.

Last update: 2025-05-26 04:38:26 UTC


README

A custom Laravel mail transport driver that sends emails through a centralized HTTP API instead of SMTP. Useful for routing all email traffic through services like Mailgun, Mailpit, or internal email proxy APIs.

📡 Default endpoint: https://smtp.africoders.com/

🚀 Features

  • Custom mail transport using HTTP API
  • Compatible with Laravel 8, 10, and 11
  • Configurable API key and endpoint
  • Fully pluggable and override-ready
  • Designed for mail proxies and external SMTP wrappers

📦 Installation

composer require africoders/laravel-mailer

⚙️ Configuration

1. Publish the package config:

php artisan vendor:publish --tag=africoders-mailer-config

This publishes config/africoders-mailer.php:

return [
    'endpoint' => env('MAIL_CUSTOM_API_ENDPOINT', 'https://smtp.africoders.com/'),
    'api_key'  => env('MAIL_CUSTOM_API_KEY', 'changeme'),
];

2. Update your .env:

MAIL_MAILER=customapi
MAIL_CUSTOM_API_ENDPOINT=https://smtp.africoders.com/
MAIL_CUSTOM_API_KEY=12344343

📤 Sending Emails

Once configured, all emails sent via Laravel's Mail::to()->send() will be routed through your custom API transport.

Example JSON payload sent to the endpoint:

{
  "apiKey": "12344343",
  "from_name": "Africoders",
  "to": "user@example.com",
  "subject": "Hello",
  "html": "<h1>This is a test email</h1>"
}

🛠 API Expectations

Your API should accept a POST request with:

  • apiKey – required, must match configured key
  • to – recipient email
  • subject – subject of the email
  • html – email body (HTML)
  • from_address – optional (defaults to config)
  • from_name – optional (defaults to config)

🔐 Security

Make sure your API endpoint is protected using an apiKey or bearer token.

🤝 Contributing

Pull requests welcome! For major changes, please open an issue first to discuss what you would like to change.

📝 License

MIT © Africoders