From 9792a403cbe4d6b8f148708e1c631e8f83c096c6 Mon Sep 17 00:00:00 2001 From: Adam Eehan Date: Sat, 7 Nov 2026 21:09:03 +0530 Subject: [PATCH] feat(newsletter): implement sovereign double opt-in confirmation and welcome workflow --- api/_emailTemplates.js | 271 +++++++++++++++++++++++++++++++++++++++++ api/_mailer.js | 71 +++++++++++ api/subscribe.js | 65 ++++++---- api/verify.js | 174 ++++++++++++++++++++++++++ package.json | 9 ++ 5 files changed, 566 insertions(+), 24 deletions(-) create mode 100644 api/_emailTemplates.js create mode 100644 api/_mailer.js create mode 100644 api/verify.js create mode 100644 package.json diff --git a/api/_emailTemplates.js b/api/_emailTemplates.js new file mode 100644 index 0000000..920a45d --- /dev/null +++ b/api/_emailTemplates.js @@ -0,0 +1,271 @@ +// Aira Corporate Email Templates +// Aesthetic: Pure Corporate Luxury matching airaaigroup.in +// Palette: Deep Royal Navy (#0a2342), Crisp Slate (#f1f5f9), Royal Blue (#1d4ed8), Pure White (#ffffff) + +export function getConfirmationEmailHtml(name, confirmUrl) { + const safeName = name ? escapeHtml(name) : "Colleague"; + const safeUrl = escapeHtml(confirmUrl); + + return ` + + + + + Confirm Your Subscription — Aira Group of Technology + + +
+ Please verify your email address to complete your subscription to Aira Group Sovereign Engineering Dispatches. +
+ + + + +
+ + + + + + + + + + + + + +
+ + + + + +
+
+ AiraGroup +
+
+ TECHNOLOGY • SOVEREIGN ENGINEERING +
+
+ + Verification + +
+
+
+ SUBSCRIPTION CONFIRMATION +
+

+ Confirm Your Subscription to Aira Group Dispatches +

+

+ Hello ${safeName}, +

+

+ Thank you for requesting to join the official Aira Group of Technology engineering dispatch list. We publish verified deep-tech architectural analyses on sovereign AI models, bare-metal kernels, and cellular mesh communication directly from Founder & CEO Er. Adam Eehan. +

+

+ To complete your subscription and verify that this email belongs to you, please click the button below: +

+ + + + + +
+ + Confirm Subscription → + +
+
+
+ Button not working? Copy and paste this URL into your browser:
+ ${safeUrl} +
+
+

+ 🔒 If you did not request this subscription, no action is required. You will never be added without explicit confirmation. +

+
+

+ Aira Group of Technology +

+

+ Sovereign Deep-Tech & AI Engineering • Kerala, India +

+

+ Privacy Policy • + Terms of Service • + Official Portal +

+
+
+ +`; +} + +export function getWelcomeEmailHtml(name) { + const safeName = name ? escapeHtml(name) : "Colleague"; + + return ` + + + + + Welcome to Aira Group — Sovereign Engineering + + +
+ Your subscription is confirmed. Welcome to Aira Group of Technology — Sovereign Engineering. Zero Dependency. +
+ + + + +
+ + + + + + + + + + + + + +
+ + + + + +
+
+ AiraGroup +
+
+ TECHNOLOGY • SOVEREIGN ENGINEERING +
+
+ + ✓ Verified Member + +
+
+
+ OFFICIAL WELCOME +
+

+ Sovereign Engineering.
Zero Dependency. +

+

+ Hello ${safeName}, +

+

+ Welcome to Aira Group of Technology. We don't just build consumer software; we engineer deep-tech sovereignty from the bare metal up. +

+

+ As a confirmed subscriber to our Dispatches, you get direct, early insights into our active research and open deployments: +

+ + + + + + + + + + + + + + +
+ + + + + +
⚡ +
Aira Sovereign Models Hub
+
+ Zero rate-limit OpenAI-compatible AI API gateway and interactive playground. +
+
+
+ + + + + +
🌐 +
AiraLang & Bare-Metal Kernel
+
+ High-performance SIMD execution engine engineered without foreign frameworks. +
+
+
+ + + + + +
📡 +
Cellular Mesh & Hardened Comms
+
+ Decentralized off-grid mesh protocols for mission-critical infrastructure. +
+
+
+ + + + + + +
+ + Explore Aira Ecosystem → + +
+ +
+

+ Er. Adam Eehan +

+

+ Founder & CEO, Aira Group of Technology +

+
+
+

+ Aira Group of Technology +

+

+ Sovereign Deep-Tech & AI Engineering • Kerala, India +

+

+ Privacy Policy • + Terms of Service • + Official Portal +

+
+
+ +`; +} + +function escapeHtml(str) { + return String(str) + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} diff --git a/api/_mailer.js b/api/_mailer.js new file mode 100644 index 0000000..3e6689d --- /dev/null +++ b/api/_mailer.js @@ -0,0 +1,71 @@ +// Aira Sovereign Mail Dispatcher +// Engineered for Aira Group of Technology (airaaigroup.in) + +export async function sendEmail({ to, toName, subject, html }) { + const RESEND_KEY = process.env.RESEND_API_KEY || ""; + const SENDER_EMAIL = process.env.SENDER_EMAIL || "noreply@airaaigroup.in"; + const SENDER_NAME = process.env.SENDER_NAME || "Aira Group of Technology"; + + // 1. Try Resend API + if (RESEND_KEY) { + try { + const resendRes = await fetch("https://api.resend.com/emails", { + method: "POST", + headers: { + "Authorization": `Bearer ${RESEND_KEY}`, + "Content-Type": "application/json", + "User-Agent": "AiraGroup-Portal/1.0" + }, + body: JSON.stringify({ + from: `${SENDER_NAME} <${SENDER_EMAIL}>`, + to: [to], + subject: subject, + html: html + }) + }); + + const resendData = await resendRes.json(); + if (resendRes.ok) { + console.log(`[Resend Success] Email sent to ${to}:`, resendData.id); + return { success: true, provider: "resend", id: resendData.id }; + } else { + console.warn(`[Resend Warning] (${resendRes.status}):`, JSON.stringify(resendData)); + } + } catch (err) { + console.error("[Resend Exception]:", err.message); + } + } + + // 2. Try SMTP if environment credentials exist + if (process.env.SMTP_HOST && process.env.SMTP_USER && process.env.SMTP_PASS) { + try { + const nodemailer = await import("nodemailer"); + const transporter = nodemailer.createTransport({ + host: process.env.SMTP_HOST, + port: parseInt(process.env.SMTP_PORT || "465", 10), + secure: process.env.SMTP_SECURE !== "false", + auth: { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASS + } + }); + + const info = await transporter.sendMail({ + from: `"${SENDER_NAME}" <${process.env.SMTP_USER}>`, + to: to, + subject: subject, + html: html + }); + + console.log(`[SMTP Success] Email sent to ${to}:`, info.messageId); + return { success: true, provider: "smtp", id: info.messageId }; + } catch (err) { + console.error("[SMTP Exception]:", err.message); + } + } + + return { + success: false, + error: "No active email dispatch provider succeeded." + }; +} diff --git a/api/subscribe.js b/api/subscribe.js index b12eacd..7b8378e 100644 --- a/api/subscribe.js +++ b/api/subscribe.js @@ -1,8 +1,15 @@ -// Vercel Serverless Function: Automated Hostinger Reach Subscription +// Vercel Serverless Function: Automated Double Opt-In Subscription // Engineered for Aira Group of Technology (airaaigroup.in) +import { generateVerifyToken } from "./verify.js"; +import { getConfirmationEmailHtml } from "./_emailTemplates.js"; +import { sendEmail } from "./_mailer.js"; + +const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c"; +const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6"; + export default async function handler(req, res) { - // Set CORS headers + // CORS headers res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS"); res.setHeader("Access-Control-Allow-Headers", "Content-Type"); @@ -22,38 +29,48 @@ export default async function handler(req, res) { return res.status(400).json({ error: "Valid email address is required." }); } - const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c"; - const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6"; - const REACH_URL = `https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`; + const cleanEmail = email.trim().toLowerCase(); + const cleanName = name ? name.trim() : ""; - const payload = { - email: email.trim().toLowerCase(), - name: name ? name.trim() : null - }; + // 1. Generate secure cryptographic verification link + const token = generateVerifyToken(cleanEmail); + const host = req.headers["x-forwarded-host"] || req.headers.host || "www.airaaigroup.in"; + const proto = req.headers["x-forwarded-proto"] || "https"; + const verifyUrl = `${proto}://${host}/api/verify?email=${encodeURIComponent(cleanEmail)}&token=${token}${cleanName ? `&name=${encodeURIComponent(cleanName)}` : ""}`; - const hostingerRes = await fetch(REACH_URL, { - method: "POST", - headers: { - "Authorization": `Bearer ${HOSTINGER_TOKEN}`, - "Content-Type": "application/json", - "User-Agent": "AiraGroup-Portal/1.0" - }, - body: JSON.stringify(payload) + // 2. Dispatch Confirmation Email + const confirmHtml = getConfirmationEmailHtml(cleanName, verifyUrl); + const mailResult = await sendEmail({ + to: cleanEmail, + toName: cleanName, + subject: "Verify Your Subscription — Aira Group of Technology", + html: confirmHtml }); - const responseText = await hostingerRes.text(); + console.log("[Confirmation Mail Dispatch Result]:", mailResult); - if (!hostingerRes.ok) { - console.error("[Hostinger Reach Error]:", hostingerRes.status, responseText); - return res.status(hostingerRes.status).json({ - error: "Failed to sync subscription with Hostinger.", - details: responseText + // 3. Register contact with Hostinger Reach + try { + const reachRes = await fetch(`https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`, { + method: "POST", + headers: { + "Authorization": `Bearer ${HOSTINGER_TOKEN}`, + "Content-Type": "application/json", + "User-Agent": "AiraGroup-Portal/1.0" + }, + body: JSON.stringify({ + email: cleanEmail, + name: cleanName || null + }) }); + console.log("[Hostinger Reach Contact Sync]:", reachRes.status); + } catch (err) { + console.warn("[Hostinger Sync Warning]:", err.message); } return res.status(200).json({ success: true, - message: "Subscription confirmed! Please check your email to verify your subscription." + message: "Confirmation email sent! Please check your inbox and click the verification button." }); } catch (err) { console.error("[Subscribe API Exception]:", err); diff --git a/api/verify.js b/api/verify.js new file mode 100644 index 0000000..1336441 --- /dev/null +++ b/api/verify.js @@ -0,0 +1,174 @@ +// Vercel Serverless Function: Double Opt-In Email Verification +// Engineered for Aira Group of Technology (airaaigroup.in) + +import crypto from "crypto"; +import { getWelcomeEmailHtml } from "./_emailTemplates.js"; +import { sendEmail } from "./_mailer.js"; + +const SECRET = process.env.VERIFY_SECRET || "aira-sovereign-secret-token-key-2026"; +const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c"; +const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6"; + +export function generateVerifyToken(email) { + return crypto.createHmac("sha256", SECRET).update(email.trim().toLowerCase()).digest("hex"); +} + +export default async function handler(req, res) { + const { email, token, name } = req.query || {}; + + if (!email || !token) { + return res.status(400).send(renderStatusHtml(false, "Invalid Verification Link", "The confirmation link is missing required parameters. Please subscribe again from our portal.")); + } + + const cleanEmail = email.trim().toLowerCase(); + const displayName = name ? decodeURIComponent(name).trim() : ""; + const expectedToken = generateVerifyToken(cleanEmail); + + if (token !== expectedToken) { + return res.status(403).send(renderStatusHtml(false, "Verification Link Invalid", "This confirmation link is invalid or has expired. Please subscribe again from our portal.")); + } + + // 1. Sync confirmed subscriber with Hostinger Reach + try { + const reachRes = await fetch(`https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`, { + method: "POST", + headers: { + "Authorization": `Bearer ${HOSTINGER_TOKEN}`, + "Content-Type": "application/json", + "User-Agent": "AiraGroup-Portal/1.0" + }, + body: JSON.stringify({ + email: cleanEmail, + name: displayName || null, + subscription_status: "subscribed" + }) + }); + console.log("[Hostinger Reach Confirmed Sync]:", reachRes.status); + } catch (err) { + console.error("[Hostinger Reach Sync Error]:", err.message); + } + + // 2. Dispatch Welcome Email + try { + const welcomeHtml = getWelcomeEmailHtml(displayName); + await sendEmail({ + to: cleanEmail, + toName: displayName, + subject: "Welcome to Aira Group — Sovereign Engineering. Zero Dependency", + html: welcomeHtml + }); + } catch (err) { + console.error("[Welcome Email Dispatch Error]:", err.message); + } + + // 3. Render Clean Corporate Success Page + return res.status(200).send(renderStatusHtml( + true, + "Subscription Confirmed! 🎉", + `Thank you for confirming your email (${escapeHtml(cleanEmail)}). You are now an active member of Aira Group Sovereign Engineering Dispatches. Your official welcome dispatch has been sent to your inbox.` + )); +} + +function renderStatusHtml(isSuccess, title, message) { + const accentColor = isSuccess ? "#10b981" : "#ef4444"; + const icon = isSuccess ? "✓" : "!"; + + return ` + + + + + ${escapeHtml(title)} — Aira Group of Technology + + + + +
+
${icon}
+

${escapeHtml(title)}

+

${message}

+ ← Return to Aira Group Homepage + +
+ +`; +} + +function escapeHtml(str) { + return String(str) + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..35a2176 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "aira-company-website", + "version": "1.0.0", + "type": "module", + "description": "Official Website & Serverless Endpoints for Aira Group of Technology", + "dependencies": { + "nodemailer": "^6.9.16" + } +}