{"record":{"id":"f1da3ae7d1ea76b5","repo":"Billionmail/BillionMail","slug":"port-must-be-between-1-65535","errorCode":null,"errorMessage":"port must be between 1-65535","messagePattern":"port must be between 1-65535","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/controller/settings/settings.go","lineNumber":216,"sourceCode":"\t\t}\n\n\tcase \"ADMIN_PASSWORD\", \"admin_password\":\n\t\tif len(value) < 4 {\n\t\t\treturn fmt.Errorf(\"password length must be at least 4 characters\")\n\t\t}\n\n\tcase \"BILLIONMAIL_HOSTNAME\", \"billionmail_hostname\":\n\t\t// Hostname: allowed letters, numbers, dots, hyphens\n\t\tif !public.IsValidHostname(value) {\n\t\t\treturn fmt.Errorf(\"hostname format is incorrect\")\n\t\t}\n\n\tcase \"SMTP_PORT\", \"SMTPS_PORT\", \"SUBMISSION_PORT\", \"IMAP_PORT\", \"IMAPS_PORT\", \"POP_PORT\", \"POPS_PORT\", \"HTTP_PORT\", \"HTTPS_PORT\", \"REDIS_PORT\",\n\t\t\"smtp\", \"smtps\", \"submission\", \"imap\", \"imaps\", \"pop\", \"pops\", \"http\", \"https\", \"redis_port\":\n\t\t// Port: 1-65535\n\t\tport := public.ParseInt(value)\n\t\tif port < 1 || port > 65535 {\n\t\t\treturn fmt.Errorf(\"port must be between 1-65535\")\n\t\t}\n\n\tcase \"IPV4_NETWORK\", \"ipv4_network\":\n\t\t// IPv4 network: CIDR format\n\t\tif !public.IsValidCIDR(value) {\n\t\t\treturn fmt.Errorf(\"IPv4 network format is incorrect, please use CIDR format (e.g. 192.168.1.0/24)\")\n\t\t}\n\n\tcase \"TZ\", \"timezone\":\n\t\t// Timezone: check if it is a valid timezone\n\t\tif !public.IsValidTimezone(value) {\n\t\t\treturn fmt.Errorf(\"invalid timezone\")\n\t\t}\n\n\tcase \"FAIL2BAN_INIT\", \"fail2ban\":\n\t\t// fail2ban: only allowed y/n or 1/0\n\t\tif value != \"y\" && value != \"n\" && value != \"1\" && value != \"0\" {\n\t\t\treturn fmt.Errorf(\"fail2ban value can only be y/n or 1/0\")","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/controller/settings/settings.go#L198-L234","documentation":"validateConfigValue parses port-type config keys (SMTP_PORT, IMAP_PORT, HTTP_PORT, etc., and their lowercase aliases) with public.ParseInt and requires the result to be in 1-65535. Ports outside that range cannot be bound by the mail services, so the value is rejected before being saved.","triggerScenarios":"Setting any port key (e.g. SMTP_PORT) to 0, a negative number, a number above 65535, or a non-numeric string that ParseInt maps to an out-of-range value.","commonSituations":"Copy-paste errors including the plus sign or service name ('SMTP 25'), typos like 655360, empty or blank strings, and attempts to disable a service by setting its port to 0.","solutions":["Set the port to an integer between 1 and 65535 (e.g. 25, 465, 587, 993)","Check for accidental concatenation of the port with other text before sending","Ensure the value is a plain decimal string with no units or spaces","If the service should be disabled, use the service's enable/disable flag instead of port 0"],"exampleFix":"// before\nSMTP_PORT = 0\n// after\nSMTP_PORT = 25","handlingStrategy":"validation","validationCode":"const p = Number(port);\nif (!Number.isInteger(p) || p < 1 || p > 65535) throw new Error('port must be between 1-65535');","typeGuard":"function isValidPort(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535;\n}","tryCatchPattern":"try {\n  await api.setSystemConfigKey('SMTP_PORT', String(port));\n} catch (e) {\n  if (String(e.message).includes('port must be between')) {\n    notify('Enter a TCP port from 1 to 65535');\n  } else throw e;\n}","preventionTips":["Always send ports as plain decimal strings without units","Never use 0 to 'disable' a service — use its toggle flag","Validate with Number.isInteger and range check before submit","Watch for string concatenation bugs building the port value"],"tags":["validation","config","port"],"backgroundTag":"invalid-port-range","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"}