From 9115bc96309706af91d19dc4f39ede0a93913fae Mon Sep 17 00:00:00 2001 From: Ghassan Yusuf Date: Tue, 26 May 2026 16:29:56 +0300 Subject: [PATCH] fix: build Mailer directly in sendTestEmail to avoid Mailer[name] not defined error --- app/Http/Controllers/MailAccountController.php | 9 +++++++-- app/Providers/AppServiceProvider.php | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/MailAccountController.php b/app/Http/Controllers/MailAccountController.php index 34d8a29..abd51f4 100644 --- a/app/Http/Controllers/MailAccountController.php +++ b/app/Http/Controllers/MailAccountController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Models\MailAccount; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Mail; use PromoSeven\AzureMailer\Graph\TokenManager; class MailAccountController extends Controller @@ -69,7 +68,13 @@ class MailAccountController extends Controller { $request->validate(['to' => ['required', 'email', 'max:255']]); try { - Mail::mailer($mailAccount->name)->raw( + $mailer = new \Illuminate\Mail\Mailer( + $mailAccount->name, + app('view'), + new \Symfony\Component\Mailer\Mailer($mailAccount->buildTransport()), + app('events') + ); + $mailer->raw( 'This is a test email from SteelERP. Your mail account "' . $mailAccount->label . '" is working correctly.', function ($message) use ($request, $mailAccount) { $message->to($request->to) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6e9a61a..c4af443 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -28,6 +28,7 @@ class AppServiceProvider extends ServiceProvider $this->callAfterResolving(MailManager::class, function (MailManager $manager) { try { foreach (MailAccount::all() as $account) { + config(["mail.mailers.{$account->name}" => ['transport' => $account->name]]); $manager->extend($account->name, fn () => $account->buildTransport()); } } catch (\Exception) {