newsman / laravel-newsman-smtp
Laravel mail transport driver for NewsMAN SMTP
Requires
- php: ^8.1
- illuminate/mail: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- symfony/mailer: ^6.0|^7.0
README
A custom Laravel mail driver for NewsMAN via the SMTP API (message.send_raw
endpoint).
This driver sends the full MIME message generated by Laravel/Symfony (headers, HTML/text parts, attachments, inline images) without extra transformations.
Vendor:
newsman
• Package:laravel-newsman-smtp
✨ Features
- Custom Symfony Mailer transport:
newsman
- Interactive setup (no need to edit
.env
) - Global
from_address
/from_name
configuration - Dedicated logging channel with request/response and sensitive data redacted
- Artisan commands for setup, testing, and uninstall
- Auto-injects into
config('mail.mailers')
(no manual config edits)
📦 Requirements
- PHP 8.1+
- Laravel 10.x / 11.x
- Typical PHP extensions (mbstring, json, etc.)
🚀 Installation
composer require newsman/laravel-newsman-smtp
🛠️ Setup (no .env
needed)
Run interactive setup (stores credentials in storage/app/newsman/credentials.php
and sets from_*
):
php artisan newsman:setup
# Prompts: Account ID, API Key, From address, From name
Clear caches (the setup command already does this, but you can run manually if needed):
php artisan config:clear php artisan cache:clear
✉️ Usage
A) Quick test (plain text)
php artisan newsman:test you@example.com
B) Send HTML directly
Mail::mailer('newsman')->html('<h1>Hello</h1><p>This is HTML!</p>', function ($m) { $m->to('you@example.com')->subject('HTML test'); });
C) Full Mailable (HTML + plain + attachment + inline image)
use Illuminate\Mail\Mailable; use Symfony\Component\Mime\Email; class InvoiceMail extends Mailable { public function build() { return $this->subject('Your Invoice') ->view('emails.invoice') // HTML view ->text('emails.invoice_plain') // Plain text view ->attach(storage_path('app/invoices/123.pdf'), [ 'as' => 'Invoice-123.pdf', 'mime' => 'application/pdf' ]) ->withSymfonyMessage(function (Email $email) { $email->getHeaders()->addTextHeader('X-Track', 'invoice-123'); $email->embedFromPath(public_path('logo.png'), 'logo_cid', 'image/png'); }); } }
In HTML view:
<img src="cid:logo_cid" alt="Logo" />
The driver sends the raw MIME to NewsMAN (
mime_message
), so HTML, text, attachments, and inline images are preserved.
🔧 Artisan Commands
-
Interactive setup (API key, Account ID, From info):
php artisan newsman:setup # Non-interactive options: # --account-id=... --api-key=... --from-address=... --from-name=... --endpoint=...
-
Send test email:
php artisan newsman:test you@example.com --subject="NewsMAN Test"
-
Uninstall (reset to smtp, clear storage and caches):
php artisan newsman:uninstall # Keep credentials if you plan to reinstall later: php artisan newsman:uninstall --keep
🧾 Logging
The package adds a dedicated log channel: storage/logs/newsman.log
.
- Logs request (endpoint, subject, recipients) and response (status, headers, body/json).
- Sensitive fields (
api_key
,mime_message
) are REDACTED.
Config (config/newsman.php
):
'log' => [ 'enabled' => true, 'channel' => 'newsman', 'level' => 'info', 'redact' => ['api_key','mime_message'], 'requests' => true, 'responses' => true, ], 'http' => [ 'timeout' => 15, 'retry' => ['times' => 2, 'sleep' => 200], // ms 'debug' => false, // if true → Guzzle debug logged to laravel.log ],
View logs:
tail -f storage/logs/newsman.log
🧹 Cache & config
After modifying credentials, endpoint, or logging:
php artisan config:clear php artisan cache:clear composer dump-autoload
🆘 Troubleshooting
Mailer [newsman] is not defined
- Ensure the package is installed and provider registers:
MailManager::extend('newsman', ...)
config('mail.mailers.newsman')
inboot()
- Run:
php artisan config:clear && php artisan cache:clear
- Check in Tinker:
config('mail.mailers')
→ should includenewsman
.
From defaults to no-reply@example.com
- Verify
storage/app/newsman/credentials.php
hasfrom_address
/from_name
. - In Tinker:
config('newsman.from_address') config('mail.from')
Error AbstractTransport::$dispatcher must not be accessed before initialization
- Ensure your
NewsmanTransport
constructor calls:parent::__construct($dispatcher, $logger);
Minimum-stability / cannot find version
- Install with
dev-main
or tag a version (v1.0.0
) and require with^1.0
.
🧽 Uninstall
-
Reset to Laravel’s default mailer (
smtp
):php artisan newsman:uninstall
-
Remove the package:
composer remove newsman/laravel-newsman-smtp