{"record":{"id":"e0ecf9e5aef4ae4a","repo":"hcengineering/platform","slug":"missing-env-variables-for-smtp-configuration-mi","errorCode":null,"errorMessage":"Missing env variables for SMTP configuration: ${missingKeys.join(', ')}","messagePattern":"Missing env variables for SMTP configuration: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/mail/pod-mail/src/config.ts","lineNumber":132,"sourceCode":"  return {\n    AccessKey: accessKey as string,\n    SecretKey: secretKey as string,\n    Region: region as string\n  }\n}\n\nconst buildSmtpConfig = (): SmtpConfig => {\n  const host = process.env[envMap.SmtpHost]\n  const port = parseNumber(process.env[envMap.SmtpPort])\n  const username = process.env[envMap.SmtpUsername]\n  const password = process.env[envMap.SmtpPassword]\n  const tlsMode = normalizeTlsMode(process.env[envMap.SmtpTlsMode])\n  const debugLog = process.env[envMap.SmtpDebugLog]?.toLowerCase() === 'true'\n  const allowSelfSigned = process.env[envMap.SmtpAllowSelfSigned]?.toLowerCase() === 'true'\n\n  if (isEmpty(host) || port === undefined) {\n    const missingKeys = [isEmpty(host) && 'SMTP_HOST', port === undefined && 'SMTP_PORT'].filter(Boolean)\n    throw Error(`Missing env variables for SMTP configuration: ${missingKeys.join(', ')}`)\n  }\n\n  return {\n    Host: host as string,\n    Port: port,\n    Username: username,\n    Password: password,\n    TlsMode: tlsMode ?? TlsOptions.UPGRADE,\n    DebugLog: debugLog,\n    AllowSelfSigned: allowSelfSigned\n  }\n}\n\nconst config: Config = (() => {\n  const port = parseNumber(process.env[envMap.Port])\n  if (port === undefined) {\n    throw Error('Missing env variable: Port')\n  }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/mail/pod-mail/src/config.ts#L114-L150","documentation":"buildSmtpConfig validates the minimum SMTP settings. If SMTP_HOST is missing or SMTP_PORT is unset/unparseable while SMTP mode is active, it throws this error naming the missing keys (SMTP_HOST, SMTP_PORT).","triggerScenarios":"Setting SMTP_HOST without SMTP_PORT, or SMTP_PORT set to a non-numeric value that parseNumber rejects, while SMTP configuration is enabled in pod-mail.","commonSituations":"Choosing SMTP delivery but only supplying host credentials and forgetting the port (usually 587 or 465); port given as an empty string; config split across env files where one file is not loaded.","solutions":["Set both SMTP_HOST and SMTP_PORT (numeric, e.g. 587) in the environment.","Read the error text — it lists exactly which keys are missing.","Verify SMTP_PORT is a plain integer; quoted or whitespace values can fail parsing.","If you intended SES delivery, remove SMTP_HOST so the SMTP path isn't selected."],"exampleFix":"// before\nSMTP_HOST=smtp.example.com\n// after\nSMTP_HOST=smtp.example.com\nSMTP_PORT=587","handlingStrategy":"validation","validationCode":"if (process.env.SMTP_HOST) { // SMTP path active\n  const missing = [];\n  if (!process.env.SMTP_HOST) missing.push('SMTP_HOST');\n  if (!process.env.SMTP_PORT || Number.isNaN(Number(process.env.SMTP_PORT))) missing.push('SMTP_PORT');\n  if (missing.length) throw new Error(`Missing SMTP env vars: ${missing.join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await import('./config');\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Missing env variables for SMTP')) {\n    console.error(`SMTP setup incomplete: ${err.message}`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Always pair SMTP_HOST with a numeric SMTP_PORT (587 for STARTTLS, 465 for implicit TLS).","Verify the port parses as an integer — no quotes, units, or whitespace.","Keep SMTP variables together in a single env file/secret so none are dropped.","Remove SMTP_HOST entirely if you intend to use SES."],"tags":["env","configuration","smtp","startup"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}