Lines 87-127javascript
87 let notifyCtx = null; // set when an authorized 4brains.in sender is configured
89 if (preset.type === "resend") {
90 // IntraApp(Postmaster) → Resend API. Only an API key + from address.
91 const apiKey = (await password({ message: "Resend API key (re_...):", mask: "*" })).trim();
92 const from = (await input({ message: "From address:", default: "" })).trim();
93 await ensureOfficialAllowed(from);
94 if (isOfficialMailDomain(from)) updateEnvFile(envPath, "OFFICIAL_MAIL_AUTHORIZED", "1");
95 if (apiKey) updateEnvFile(envPath, "RESEND_API_KEY", apiKey);
96 if (from) updateEnvFile(envPath, "MAIL_FROM", from);
98 summary.push(from ? `From: ${from}` : "From: (set MAIL_FROM in .env)");
99 if (isOfficialMailDomain(from) && apiKey) notifyCtx = { kind: "resend", from, apiKey };
101 // Custom SMTP → nodemailer. TLS selects the port (465 vs 587).
102 const host = (await input({ message: "SMTP host:", default: preset.host || "" })).trim();
103 const secure = await confirm({ message: "Use TLS (port 465)? (No = port 587)", default: false });
104 const defPort = secure ? 465 : 587;
105 const port = (await input({ message: "SMTP port:", default: String(defPort) })).trim();
106 const user = (await input({ message: "SMTP user:", default: "" })).trim();
107 const pass = (await password({ message: "SMTP password:", mask: "*" })).trim();
108 const from = (await input({ message: "From address:", default: user })).trim();
109 await ensureOfficialAllowed(from || user);
110 if (isOfficialMailDomain(from || user)) updateEnvFile(envPath, "OFFICIAL_MAIL_AUTHORIZED", "1");
111 updateEnvFile(envPath, "SMTP_HOST", host);
112 updateEnvFile(envPath, "SMTP_PORT", port || String(defPort));
113 updateEnvFile(envPath, "SMTP_SECURE", secure ? "true" : "false");
114 updateEnvFile(envPath, "SMTP_USER", user);
115 if (pass) updateEnvFile(envPath, "SMTP_PASS", pass);
116 updateEnvFile(envPath, "SMTP_FROM", from || user);
118 summary.push(`Host: ${host}:${port || defPort}`);
119 if (isOfficialMailDomain(from || user)) notifyCtx = { kind: "smtp", from: from || user, smtp: { host, port: port || defPort, secure, user, pass } };
123 showFileAction("updated", ".env");
125 fs.mkdirSync(dir, { recursive: true });
126 // Rewrite the mailer only if missing or on the old single-backend version.
127 if (!fs.existsSync(mailerPath) || !fs.readFileSync(mailerPath, "utf8").includes("MAIL_PROVIDER")) {