SMTP: extend env parsing (domain/auth/starttls); add unit test with mocked TLS for sendSmtpMail; extend SmtpConfig; docs to set .env locally
This commit is contained in:
parent
53c76a0289
commit
81fd572e48
3 changed files with 98 additions and 1 deletions
|
|
@ -8,8 +8,11 @@ const envSchema = z.object({
|
|||
NEXT_PUBLIC_APP_URL: z.string().url().optional(),
|
||||
SMTP_ADDRESS: z.string().optional(),
|
||||
SMTP_PORT: z.coerce.number().optional(),
|
||||
SMTP_DOMAIN: z.string().optional(),
|
||||
SMTP_USERNAME: z.string().optional(),
|
||||
SMTP_PASSWORD: z.string().optional(),
|
||||
SMTP_AUTHENTICATION: z.string().optional(),
|
||||
SMTP_ENABLE_STARTTLS_AUTO: z.string().optional(),
|
||||
SMTP_TLS: z.string().optional(),
|
||||
MAILER_SENDER_EMAIL: z.string().optional(),
|
||||
})
|
||||
|
|
@ -31,9 +34,12 @@ export const env = {
|
|||
? {
|
||||
host: parsed.data.SMTP_ADDRESS,
|
||||
port: parsed.data.SMTP_PORT ?? 465,
|
||||
domain: parsed.data.SMTP_DOMAIN,
|
||||
username: parsed.data.SMTP_USERNAME,
|
||||
password: parsed.data.SMTP_PASSWORD,
|
||||
tls: (parsed.data.SMTP_TLS ?? "true").toLowerCase() === "true",
|
||||
starttls: (parsed.data.SMTP_ENABLE_STARTTLS_AUTO ?? "false").toLowerCase() === "true",
|
||||
auth: parsed.data.SMTP_AUTHENTICATION ?? "login",
|
||||
from: parsed.data.MAILER_SENDER_EMAIL ?? "no-reply@example.com",
|
||||
}
|
||||
: null,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ type SmtpConfig = {
|
|||
username: string
|
||||
password: string
|
||||
from: string
|
||||
tls?: boolean
|
||||
}
|
||||
|
||||
function b64(input: string) {
|
||||
|
|
@ -66,4 +67,3 @@ export async function sendSmtpMail(cfg: SmtpConfig, to: string, subject: string,
|
|||
socket.on("error", reject)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue