Catching Mail Sending Exception

My client STMP server (MS Exchange) is often crashing or not responding for some reason.
What is the good way to catch email sending exception to continue the execution of the rest of the code ?

thanks

You could do a try catch block and report the exception to the log using ApplicationException

something like:

try {
    // Mail Code here
} catch (ApplicationException $ex) {
    Log::error($ex->getMessage());
}
1 Like

Thanks @artistro08
I can try this, but the fact is the error is happening in the symfony class SMTPTransport

No problem.

Hmm, might have run into a bug then. Iā€™ll let the vets help :sweat_smile:

Can I ask, what kind of error?

I had issues with my SMTP as well in OC 3.x. My hoster doesnā€™t use MS Exchange though.

Here would be my fix:

Thanks @maki3000 I will have a look

the error returned is ā€œ550 5.7.1 Relaying deniedā€, thatā€™s all

anyone received this error previosuly

Symfony\Component\Mailer\Exception\TransportException: Expected response code "250/251/252" but got code "550", with message "550 5.7.1 Relaying denied". in /var/www/html/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:307
Stack trace:
#0 /var/www/html/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(182): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->assertResponseCode()
#1 /var/www/html/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(240): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->executeCommand()
#2 /var/www/html/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(201): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->doRcptToCommand()
#3 /var/www/html/vendor/symfony/mailer/Transport/AbstractTransport.php(69): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->doSend()
#4 /var/www/html/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(136): Symfony\Component\Mailer\Transport\AbstractTransport->send()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(523): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send()
#6 /var/www/html/vendor/october/rain/src/Mail/Mailer.php(124): Illuminate\Mail\Mailer->sendSymfonyMessage()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(212): October\Rain\Mail\Mailer->send()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\Mail\Mailable->Illuminate\Mail\{closure}()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(213): Illuminate\Mail\Mailable->withLocale()
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php(74): Illuminate\Mail\Mailable->send()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Mail\SendQueuedMailable->handle()
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(661): Illuminate\Container\BoundMethod::call()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(124): Illuminate\Bus\Dispatcher->dispatchNow()
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(126): Illuminate\Pipeline\Pipeline->then()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(43): Illuminate\Queue\Jobs\Job->fire()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php(57): Illuminate\Queue\SyncQueue->push()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(233): Illuminate\Queue\Queue->pushOn()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(421): Illuminate\Mail\Mailable->queue()
#30 /var/www/html/vendor/october/rain/src/Mail/Mailer.php(221): Illuminate\Mail\Mailer->queue()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php(554): October\Rain\Mail\Mailer->queue()
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): Illuminate\Mail\MailManager->__call()
#33 /var/www/html/plugins/voilaah/astar/classes/events/MailingEventHandler.php(673): Illuminate\Support\Facades\Facade::__callStatic()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(441): Voilaah\Astar\Classes\Events\MailingEventHandler->memberRequestStatusChanged()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}()
#36 /var/www/html/vendor/october/rain/src/Events/PriorityDispatcher.php(94): Illuminate\Events\Dispatcher->dispatch()
#37 /var/www/html/vendor/october/rain/src/Events/PriorityDispatcher.php(61): October\Rain\Events\PriorityDispatcher->fireEvent()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): October\Rain\Events\PriorityDispatcher->fire()
#39 /var/www/html/plugins/voilaah/astar/models/Group.php(281): Illuminate\Support\Facades\Facade::__callStatic()
#40 /var/www/html/plugins/voilaah/astar/controllers/Groups.php(183): Voilaah\Astar\Models\Group->modifyRole()
#41 /var/www/html/modules/system/traits/DependencyMaker.php(29): Voilaah\Astar\Controllers\Groups->preview_onApprove()
#42 /var/www/html/modules/backend/classes/Controller.php(598): Backend\Classes\Controller->makeCallMethod()
#43 /var/www/html/modules/backend/classes/Controller.php(448): Backend\Classes\Controller->runAjaxHandler()
#44 /var/www/html/modules/backend/classes/Controller.php(256): Backend\Classes\Controller->execAjaxHandlers()
#45 /var/www/html/modules/backend/classes/BackendController.php(132): Backend\Classes\Controller->run()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Backend\Classes\BackendController->run()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Route->run()
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#52 /var/www/html/plugins/vdlp/twofactorauthentication/classes/TwoFactorMiddleware.php(47): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#53 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Vdlp\TwoFactorAuthentication\Classes\TwoFactorMiddleware->handle()
#54 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#56 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#58 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#60 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle()
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#62 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#64 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#65 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#66 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Pipeline\Pipeline->then()
#67 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack()
#68 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute()
#69 /var/www/html/vendor/october/rain/src/Router/CoreRouter.php(32): Illuminate\Routing\Router->dispatchToRoute()
#70 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): October\Rain\Router\CoreRouter->dispatch()
#71 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#72 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 /var/www/html/vendor/october/rain/src/Foundation/Http/Middleware/CheckForMaintenanceMode.php(23): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#74 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): October\Rain\Foundation\Http\Middleware\CheckForMaintenanceMode->handle()
#75 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#76 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then()
#77 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#78 /var/www/html/index.php(43): Illuminate\Foundation\Http\Kernel->handle()

solution here.

to add the key ā€˜local_domainā€™ for the smtp driver

2 Likes