{"record":{"id":"6c77c5627ea4bf38","repo":"MHSanaei/3x-ui","slug":"email-service-not-available","errorCode":null,"errorMessage":"email service not available","messagePattern":"email service not available","errorType":"http","errorClass":null,"httpStatus":200,"severity":"warning","filePath":"internal/web/controller/setting.go","lineNumber":274,"sourceCode":"}\n\nfunc (a *SettingController) setApiTokenEnabled(c *gin.Context) {\n\tid, err := strconv.Atoi(c.Param(\"id\"))\n\tif err != nil {\n\t\tjsonMsg(c, I18nWeb(c, \"pages.settings.toasts.modifySettings\"), err)\n\t\treturn\n\t}\n\tform := &apiTokenEnabledForm{}\n\tif bindErr := c.ShouldBind(form); bindErr != nil {\n\t\tjsonMsg(c, I18nWeb(c, \"pages.settings.toasts.modifySettings\"), bindErr)\n\t\treturn\n\t}\n\tjsonMsg(c, I18nWeb(c, \"pages.settings.toasts.modifySettings\"), a.apiTokenService.SetEnabled(id, form.Enabled))\n}\n\nfunc (a *SettingController) testSmtp(c *gin.Context) {\n\tif emailService == nil {\n\t\tjsonMsg(c, I18nWeb(c, \"pages.settings.smtpNotInitialized\"), errors.New(\"email service not available\"))\n\t\treturn\n\t}\n\tlogger.Info(\"SMTP test: starting...\")\n\tresult := emailService.TestConnection()\n\tif !result.Success {\n\t\tlogger.Warning(\"SMTP test failed at\", result.Stage+\":\", result.Message)\n\t\tc.JSON(200, gin.H{\n\t\t\t\"success\": false,\n\t\t\t\"stage\":   result.Stage,\n\t\t\t\"msg\":     result.Message,\n\t\t})\n\t\treturn\n\t}\n\tlogger.Info(\"SMTP test: success\")\n\tc.JSON(200, gin.H{\n\t\t\"success\": true,\n\t\t\"stage\":   result.Stage,\n\t\t\"msg\":     result.Message,","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/MHSanaei/3x-ui/blob/ad32144c42455696ea9f14e12168beac3e25f5d2/internal/web/controller/setting.go#L256-L292","documentation":"The testSmtp handler checks the package-level emailService singleton and reports it is nil — the SMTP service was never constructed at startup. The service is only initialized when the email configuration in the database is complete/valid enough to build a client, so this error usually means email settings (host, port, sender) were never saved or failed initialization during boot.","triggerScenarios":"Clicking 'test SMTP' in settings before saving any SMTP configuration; saving config that fails service construction (missing host/port); a startup ordering issue where the settings job that builds emailService has not run yet.","commonSituations":"Fresh installs; admins editing SMTP JSON directly in the DB; restart loops that skip the init job.","solutions":["Fill in and SAVE the SMTP settings first, then retry the test button","Restart the panel after saving so the startup path constructs emailService","Check panel logs for an email-service init error at boot if settings look correct"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save complete SMTP settings and restart the panel before pressing test","Surface emailService init failures at boot loudly so nil state is never a surprise","Disable the test button until SMTP settings exist"],"tags":["email","smtp","settings","initialization"],"backgroundTag":null,"analyzedSha":"ad32144c42455696ea9f14e12168beac3e25f5d2","analyzedAt":"2026-08-15T11:13:23.905Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}