{"record":{"id":"ea97b515e9208900","repo":"Billionmail/BillionMail","slug":"smtp-port-must-be-between-1-and-65535","errorCode":null,"errorMessage":"SMTP port must be between 1 and 65535","messagePattern":"SMTP port must be between 1 and 65535","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/controller/settings/settings_v1_set_blacklist_alert_settings.go","lineNumber":80,"sourceCode":"\tres.SetSuccess(public.LangCtx(ctx, \"Alert settings saved successfully and test email sent\"))\n\treturn res, nil\n}\n\nfunc validateAlertSettings(settings *v1.SetBlacklistAlertSettingsReq) error {\n\tif settings.SenderEmail == \"\" {\n\t\treturn fmt.Errorf(\"sender email is required\")\n\t}\n\n\tif !strings.Contains(settings.SenderEmail, \"@\") {\n\t\treturn fmt.Errorf(\"invalid sender email format\")\n\t}\n\n\tif settings.SMTPServer == \"\" {\n\t\treturn fmt.Errorf(\"SMTP server is required\")\n\t}\n\n\tif settings.SMTPPort < 1 || settings.SMTPPort > 65535 {\n\t\treturn fmt.Errorf(\"SMTP port must be between 1 and 65535\")\n\t}\n\n\tif settings.SMTPPassword == \"\" {\n\t\treturn fmt.Errorf(\"SMTP password is required\")\n\t}\n\n\tif len(settings.RecipientList) == 0 {\n\t\treturn fmt.Errorf(\"at least one recipient is required\")\n\t}\n\n\tfor _, recipient := range settings.RecipientList {\n\t\tif !strings.Contains(recipient, \"@\") {\n\t\t\treturn fmt.Errorf(\"invalid recipient email format: %s\", recipient)\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/controller/settings/settings_v1_set_blacklist_alert_settings.go#L62-L98","documentation":"validateAlertSettings rejects blacklist alert SMTP settings whose port is outside the valid TCP range. SMTPPort must be an integer from 1 to 65535; anything below 1 (typically the zero-value of an unset field) or above 65535 fails validation before any connection is attempted.","triggerScenarios":"Calling SetBlacklistAlertSettings with SMTPPort=0 (field omitted in the JSON payload, so GoStruct zero-value), a negative number, or a value >65535.","commonSituations":"Client omits smtpPort in the request body; frontend sends the port as a string so it fails to bind and stays 0; a typo like 655360; admin pastes a URL instead of a port.","solutions":["Set SMTPPort to the actual SMTP server port (e.g. 587 for STARTTLS, 465 for implicit TLS, 25 for relay).","Ensure the JSON request field is a number, not a string, and is explicitly included in the payload.","If port is optional, default it server-side to 587 before calling validateAlertSettings."],"exampleFix":"// before\n{\"smtpServer\":\"smtp.example.com\",\"smtpPort\":0,...}\n// after\n{\"smtpServer\":\"smtp.example.com\",\"smtpPort\":587,...}","handlingStrategy":"validation","validationCode":"const port = Number(payload.smtpPort)\nif (!Number.isInteger(port) || port < 1 || port > 65535) {\n  throw new Error(`smtpPort must be an integer 1-65535, got ${payload.smtpPort}`)\n}","typeGuard":"function isValidPort(p: unknown): p is number {\n  return typeof p === 'number' && Number.isInteger(p) && p >= 1 && p <= 65535\n}","tryCatchPattern":null,"preventionTips":["Always send smtpPort as an explicit number in the API payload","Default to 587 (STARTTLS) or 465 (implicit TLS) in the UI form","Never rely on zero-values for required numeric fields"],"tags":["validation","smtp","config"],"backgroundTag":"smtp-port-validation-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}