fix: build Mailer directly in sendTestEmail to avoid Mailer[name] not defined error
This commit is contained in:
parent
f471102b00
commit
9115bc9630
@ -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)
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user