feat(analytics-mailer): replace mailgun with stalwart smtp
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 3s
Monorepo Pipeline / 🧹 Lint (push) Failing after 1m23s
Monorepo Pipeline / 🧪 Test (push) Successful in 40s
Monorepo Pipeline / 🏗️ Build (push) Successful in 2m7s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 3s
Monorepo Pipeline / 🧹 Lint (push) Failing after 1m23s
Monorepo Pipeline / 🧪 Test (push) Successful in 40s
Monorepo Pipeline / 🏗️ Build (push) Successful in 2m7s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
This commit is contained in:
@@ -4,8 +4,7 @@ import axios from "axios";
|
||||
import { render } from "@mintel/mail";
|
||||
import { AnalyticsTemplate } from "@mintel/mail";
|
||||
import { getLast7Days, getThisMonth, getThisYear } from "./utils/time-calculator";
|
||||
import Mailgun from "mailgun.js";
|
||||
import formData from "form-data";
|
||||
import nodemailer from "nodemailer";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
@@ -15,10 +14,11 @@ const UMAMI_USERNAME = process.env.UMAMI_USERNAME;
|
||||
const UMAMI_PASSWORD = process.env.UMAMI_PASSWORD;
|
||||
const UMAMI_API_KEY = process.env.UMAMI_API_KEY;
|
||||
|
||||
const MAILGUN_API_KEY = process.env.MAILGUN_API_KEY;
|
||||
const MAILGUN_DOMAIN = process.env.MAILGUN_DOMAIN;
|
||||
const MAILGUN_SENDER = process.env.MAILGUN_SENDER || "reports@mintel.me";
|
||||
const MAILGUN_URL = process.env.MAILGUN_URL || "https://api.eu.mailgun.net";
|
||||
const SMTP_HOST = process.env.SMTP_HOST || "mail.infra.mintel.me";
|
||||
const SMTP_PORT = parseInt(process.env.SMTP_PORT || "587", 10);
|
||||
const SMTP_USER = process.env.SMTP_USER;
|
||||
const SMTP_PASS = process.env.SMTP_PASS;
|
||||
const SMTP_SENDER = process.env.SMTP_SENDER || "reports@mintel.me";
|
||||
|
||||
interface ConfigClient {
|
||||
websiteId: string;
|
||||
@@ -116,9 +116,16 @@ async function main() {
|
||||
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||
const api = axios.create({ baseURL: `${UMAMI_BASE_URL}/api`, headers, httpsAgent });
|
||||
|
||||
// Setup Mailgun
|
||||
const mailgun = new Mailgun(formData);
|
||||
const mg = mailgun.client({ username: "api", key: MAILGUN_API_KEY || "dummy", url: MAILGUN_URL });
|
||||
// Setup SMTP Transporter (Nodemailer)
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
secure: SMTP_PORT === 465,
|
||||
auth: SMTP_USER && SMTP_PASS ? {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
const timeRanges = [getLast7Days(), getThisMonth(), getThisYear()];
|
||||
|
||||
@@ -153,12 +160,12 @@ async function main() {
|
||||
await fs.writeFile(debugPath, html);
|
||||
console.log(`[DRY-RUN] Saved HTML preview to ${debugPath}`);
|
||||
} else {
|
||||
if (!MAILGUN_API_KEY) {
|
||||
throw new Error("MAILGUN_API_KEY is missing for live run.");
|
||||
if (!SMTP_HOST) {
|
||||
throw new Error("SMTP_HOST is missing for live run.");
|
||||
}
|
||||
await mg.messages.create(MAILGUN_DOMAIN!, {
|
||||
from: MAILGUN_SENDER,
|
||||
to: [client.clientEmail],
|
||||
await transporter.sendMail({
|
||||
from: SMTP_SENDER,
|
||||
to: client.clientEmail,
|
||||
subject,
|
||||
html,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user