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 App\Models\MailAccount;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use PromoSeven\AzureMailer\Graph\TokenManager;
|
use PromoSeven\AzureMailer\Graph\TokenManager;
|
||||||
|
|
||||||
class MailAccountController extends Controller
|
class MailAccountController extends Controller
|
||||||
@ -69,7 +68,13 @@ class MailAccountController extends Controller
|
|||||||
{
|
{
|
||||||
$request->validate(['to' => ['required', 'email', 'max:255']]);
|
$request->validate(['to' => ['required', 'email', 'max:255']]);
|
||||||
try {
|
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.',
|
'This is a test email from SteelERP. Your mail account "' . $mailAccount->label . '" is working correctly.',
|
||||||
function ($message) use ($request, $mailAccount) {
|
function ($message) use ($request, $mailAccount) {
|
||||||
$message->to($request->to)
|
$message->to($request->to)
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->callAfterResolving(MailManager::class, function (MailManager $manager) {
|
$this->callAfterResolving(MailManager::class, function (MailManager $manager) {
|
||||||
try {
|
try {
|
||||||
foreach (MailAccount::all() as $account) {
|
foreach (MailAccount::all() as $account) {
|
||||||
|
config(["mail.mailers.{$account->name}" => ['transport' => $account->name]]);
|
||||||
$manager->extend($account->name, fn () => $account->buildTransport());
|
$manager->extend($account->name, fn () => $account->buildTransport());
|
||||||
}
|
}
|
||||||
} catch (\Exception) {
|
} catch (\Exception) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user