()
| 4 | const logger = createLogger("smtp"); |
| 5 | |
| 6 | export const getSMTPConnectionURL = (): string | undefined => { |
| 7 | if (env.SMTP_CONNECTION_URL) { |
| 8 | return env.SMTP_CONNECTION_URL; |
| 9 | } |
| 10 | |
| 11 | const { SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD } = env; |
| 12 | if (!SMTP_HOST && !SMTP_PORT && !SMTP_USERNAME && !SMTP_PASSWORD) { |
| 13 | return undefined; |
| 14 | } |
| 15 | |
| 16 | const missing: string[] = []; |
| 17 | if (!SMTP_HOST) missing.push("SMTP_HOST"); |
| 18 | if (!SMTP_PORT) missing.push("SMTP_PORT"); |
| 19 | if (!SMTP_USERNAME) missing.push("SMTP_USERNAME"); |
| 20 | if (!SMTP_PASSWORD) missing.push("SMTP_PASSWORD"); |
| 21 | |
| 22 | if (missing.length > 0) { |
| 23 | logger.error(`Missing required SMTP environment variables: ${missing.join(", ")}. All of SMTP_HOST, SMTP_PORT, SMTP_USERNAME, and SMTP_PASSWORD must be set when not using SMTP_CONNECTION_URL.`); |
| 24 | return undefined; |
| 25 | } |
| 26 | |
| 27 | return `smtp://${SMTP_USERNAME}:${SMTP_PASSWORD}@${SMTP_HOST}:${SMTP_PORT}`; |
| 28 | } |
no outgoing calls
no test coverage detected