🌳
pt0/serverF/emailF/etherealF.mts
1import fs from 'fs'
2import nodemailer from 'nodemailer'
4import { calcReqHash } from '../calcHashF.mts'
8import { pathDownJoin } from '../pathF.mts'
10export const getAppName = () => getEnvConfOpt()?.appname ?? 'unknown'
12const getEtherealJsonPath = () => pathDownJoin(ptTmpDir, `${calcReqHash(getAppName() as string)}-ethereal.json`)
14export const clearEtherealCreds = () => {
15 fs.rmSync(getEtherealJsonPath())
18export const getCachedEtherealCreds = async () => {
19 const path = getEtherealJsonPath()
21 const readJson = await readJsonIfExist(path)
22 if (readJson) return readJson
24 const newCreds = await withTimeout(nodemailer.createTestAccount(), 15_000)
27 fs.writeFileSync(path, JSON.stringify(newCreds))
29 return newCreds