Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An unknown error occurred when the SMTP host could not be reached #5195

Closed
mschoon85 opened this issue Sep 6, 2024 · 9 comments
Closed

An unknown error occurred when the SMTP host could not be reached #5195

mschoon85 opened this issue Sep 6, 2024 · 9 comments

Comments

@mschoon85
Copy link

Describe the Bug

Hi @ssddanbrown,

I've opted to submit a separate bug report since the same issue has arisen on both our former Bookstack server (Windows) and our current one (Linux). Errors occur when creating new pages in specific books; the pages are created, but the error remains. This issue can be replicated by changing the MAIL_HOST in the .env file to a non-existent address. It's important to note that not all books are affected by this issue. Moreover, I encounter this error even when I'm not subscribed to the book anymore. Whenever I revert the MAIL_HOST to a valid address, the problems disappear. It's probable that the issue would recur if the MAIL_HOST were unreachable at the moment of saving the page.

Please inform me if you require any information from the server logs or similar resources.

Kind regards,

Michel

Steps to Reproduce

  1. Edit the .env file.
  2. Change MAIL_HOST to a non-existent value.
  3. Identify a book that causes an error when a new page is created, possibly by following it first.

Note: The new settings with the non-existent mail host were only applied after executing php artisan config:cache. The reason for this is unclear.

Expected Behaviour

One would expect emails to accumulate in a queue until the mail host becomes available once more.

Screenshots or Additional Context

image

Browser Details

Edge

Exact BookStack Version

24.05.3

@mschoon85
Copy link
Author

mschoon85 commented Sep 6, 2024

When I enable debug mode:

Symfony\Component\Mailer\Exception\TransportException
Connection could not be established with host "smtp.xxx1:25": stream_socket_client(): php_network_getaddresses: getaddrinfo for smtp.xxx1 failed: No such host is known.

PHP Version: 8.3.7
BookStack Version: v24.05.3
Theme Configured: custom

Details

#0 [internal function]: Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->Symfony\Component\Mailer\Transport\Smtp\Stream\{closure}()
#1 D:\Apache24\htdocs\bookstack\vendor\ssddanbrown\symfony-mailer\Transport\Smtp\Stream\SocketStream.php(157): stream_socket_client()
#2 D:\Apache24\htdocs\bookstack\vendor\ssddanbrown\symfony-mailer\Transport\Smtp\SmtpTransport.php(276): Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->initialize()
#3 D:\Apache24\htdocs\bookstack\vendor\ssddanbrown\symfony-mailer\Transport\Smtp\SmtpTransport.php(214): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->start()
#4 D:\Apache24\htdocs\bookstack\vendor\ssddanbrown\symfony-mailer\Transport\AbstractTransport.php(69): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->doSend()
#5 D:\Apache24\htdocs\bookstack\vendor\ssddanbrown\symfony-mailer\Transport\Smtp\SmtpTransport.php(138): Symfony\Component\Mailer\Transport\AbstractTransport->send()
#6 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(573): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send()
#7 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(335): Illuminate\Mail\Mailer->sendSymfonyMessage()
#8 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\Channels\MailChannel.php(66): Illuminate\Mail\Mailer->send()
#9 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php(148): Illuminate\Notifications\Channels\MailChannel->send()
#10 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php(106): Illuminate\Notifications\NotificationSender->sendToNotifiable()
#11 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Support\Traits\Localizable.php(19): Illuminate\Notifications\NotificationSender->Illuminate\Notifications\{closure}()
#12 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php(101): Illuminate\Notifications\NotificationSender->withLocale()
#13 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\ChannelManager.php(54): Illuminate\Notifications\NotificationSender->sendNow()
#14 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\SendQueuedNotifications.php(119): Illuminate\Notifications\ChannelManager->sendNow()
#15 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(36): Illuminate\Notifications\SendQueuedNotifications->handle()
#16 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Container\Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#17 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#18 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#19 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Container\Container.php(662): Illuminate\Container\BoundMethod::call()
#20 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(128): Illuminate\Container\Container->call()
#21 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(144): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#22 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#23 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#24 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(123): Illuminate\Bus\Dispatcher->dispatchNow()
#25 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(144): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#26 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#28 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#29 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(102): Illuminate\Queue\CallQueuedHandler->call()
#30 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Queue\SyncQueue.php(43): Illuminate\Queue\Jobs\Job->fire()
#31 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(254): Illuminate\Queue\SyncQueue->push()
#32 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(230): Illuminate\Bus\Dispatcher->pushCommandToQueue()
#33 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(77): Illuminate\Bus\Dispatcher->dispatchToQueue()
#34 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php(229): Illuminate\Bus\Dispatcher->dispatch()
#35 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php(76): Illuminate\Notifications\NotificationSender->queueNotification()
#36 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\ChannelManager.php(39): Illuminate\Notifications\NotificationSender->send()
#37 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Notifications\RoutesNotifications.php(18): Illuminate\Notifications\ChannelManager->send()
#38 D:\Apache24\htdocs\bookstack\app\Activity\Notifications\Handlers\BaseNotificationHandler.php(39): BookStack\Users\Models\User->notify()
#39 D:\Apache24\htdocs\bookstack\app\Activity\Notifications\Handlers\PageCreationNotificationHandler.php(22): BookStack\Activity\Notifications\Handlers\BaseNotificationHandler->sendNotificationToUserIds()
#40 D:\Apache24\htdocs\bookstack\app\Activity\Notifications\NotificationManager.php(28): BookStack\Activity\Notifications\Handlers\PageCreationNotificationHandler->handle()
#41 D:\Apache24\htdocs\bookstack\app\Activity\Tools\ActivityLogger.php(43): BookStack\Activity\Notifications\NotificationManager->handle()
#42 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(355): BookStack\Activity\Tools\ActivityLogger->add()
#43 D:\Apache24\htdocs\bookstack\app\Entities\Repos\PageRepo.php(84): Illuminate\Support\Facades\Facade::__callStatic()
#44 D:\Apache24\htdocs\bookstack\app\Entities\Controllers\PageController.php(124): BookStack\Entities\Repos\PageRepo->publishDraft()
#45 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): BookStack\Entities\Controllers\PageController->store()
#46 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#47 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Route.php(259): Illuminate\Routing\ControllerDispatcher->dispatch()
#48 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Route.php(205): Illuminate\Routing\Route->runController()
#49 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Router.php(806): Illuminate\Routing\Route->run()
#50 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(144): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#51 D:\Apache24\htdocs\bookstack\app\Http\Middleware\Authenticate.php(23): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\Authenticate->handle()
#53 D:\Apache24\htdocs\bookstack\app\Http\Middleware\Localization.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\Localization->handle()
#55 D:\Apache24\htdocs\bookstack\app\Http\Middleware\RunThemeActions.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#56 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\RunThemeActions->handle()
#57 D:\Apache24\htdocs\bookstack\app\Http\Middleware\CheckEmailConfirmed.php(47): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#58 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\CheckEmailConfirmed->handle()
#59 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#60 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#61 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#62 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#63 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#64 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#65 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Session\Middleware\StartSession->handle()
#66 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#67 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#68 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#69 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#70 D:\Apache24\htdocs\bookstack\app\Http\Middleware\ApplyCspRules.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#71 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\ApplyCspRules->handle()
#72 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Router.php(805): Illuminate\Pipeline\Pipeline->then()
#74 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Router.php(784): Illuminate\Routing\Router->runRouteWithinStack()
#75 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Router.php(748): Illuminate\Routing\Router->runRoute()
#76 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Routing\Router.php(737): Illuminate\Routing\Router->dispatchToRoute()
#77 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(200): Illuminate\Routing\Router->dispatch()
#78 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(144): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#79 D:\Apache24\htdocs\bookstack\app\Http\Middleware\PreventResponseCaching.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#80 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\PreventResponseCaching->handle()
#81 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Http\Middleware\TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#82 D:\Apache24\htdocs\bookstack\app\Http\Middleware\TrustProxies.php(41): Illuminate\Http\Middleware\TrustProxies->handle()
#83 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): BookStack\Http\Middleware\TrustProxies->handle()
#84 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#85 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#86 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#87 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#88 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#89 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php(99): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#90 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(183): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#91 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#92 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(175): Illuminate\Pipeline\Pipeline->then()
#93 D:\Apache24\htdocs\bookstack\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(144): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#94 D:\Apache24\htdocs\bookstack\public\index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#95 {main}

@ssddanbrown
Copy link
Member

One would expect emails to accumulate in a queue until the mail host becomes available once more.

There is no queue unless you specifically enable it, which will also require a queue worker as described in our documentation:
https://www.bookstackapp.com/docs/admin/email-webhooks/#async-action-handling

Otherwise, errors will be thrown as experienced if the system is trying to mail but encounters errors.

@mschoon85
Copy link
Author

By adding QUEUE_CONNECTION=database to the .env file, the error is resolved. Emails should now be stored in the database if I'm not mistaken. I will look for a method to continuously run the Queue Worker Process in the Docker container once I have a functioning external SMTP server, as opposed to using our internal server.

Thanks @ssddanbrown !

@pnunn
Copy link

pnunn commented Sep 19, 2024

I just spent about an hour chasing this one down too when trying to add a new user. I had send the invitation checked, and because no smtp server is configured in the docker container its running in, I got unknown error. A better error message would be greatly appreciated because I was looking for errors to do with adding users, not email errors.

@ssddanbrown
Copy link
Member

@pnunn Yeah, I agree, this is likely to be the first use of email for many so adding extra specific handling for email errors for better guidance would probably be worthwhile here.
I'll update & recategorise this issue to be focused on improving the error flow here.

@ssddanbrown ssddanbrown added this to the Next Feature Release milestone Sep 19, 2024
ssddanbrown added a commit that referenced this issue Sep 29, 2024
Added specific handling to show relevant error message when user
creation fails due to invite sending errors, while also returning user
to the form with previous input.
Includes test to cover.

For #5195
@ssddanbrown
Copy link
Member

Specific handling with error display (while returning the user back to the form with previous form input) has now been added via d12e8ec, which will be part of the next feature release.

Thanks @mschoon85 and @pnunn for your input.

@mschoon85
Copy link
Author

Hi @ssddanbrown,

I have updated to BookStack v24.10, but I still encounter the error 'An unknown error occurred' whenever QUEUE_CONNECTION=database is not enabled and an invalid or unreachable SMTP server is set in the .env file.

Interestingly, not all books seem to be affected. New books and some existing books do not trigger this error. I’m wondering if this issue might be related to the books I follow or have followed in the past.

Kind regards,

Michel

@ssddanbrown
Copy link
Member

I have updated to BookStack v24.10, but I still encounter the error 'An unknown error occurred' [...]

Yeah, the update changed nothing in that regard, just added better handling for the user invite flow since that's a common first encounter for email sending.

I’m wondering if this issue might be related to the books I follow or have followed in the past.

Generally I'd expect it to be watches from other users, since notifications should not be sent for your own actions, but you can see the content you're watching from your notification preferences area in "My Account", otherwise you could peek into the watches table of the DB to quickly see if there are any watches across all users in general, although there's also notification preferences.

@mschoon85
Copy link
Author

mschoon85 commented Oct 21, 2024

@ssddanbrown, I have cleared all rows from the watches table in the test environment, but I cannot do this in production. The unknown error has now disappeared, confirming that it was caused by watches from other users. However, this still points to a deeper underlying issue: an incorrect SMTP configuration, an SMTP address that does not exist, or one that is unreachable. Would it be reasonable to create a fix to prevent users from receiving the unknown error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants