Updated mailer to use Mailtrap API
This commit is contained in:
@@ -12,3 +12,5 @@ SMTP_PASS=1253b2fe0fc47a
|
|||||||
SMTP_FROM=Playzer <no-reply@playzer.app>
|
SMTP_FROM=Playzer <no-reply@playzer.app>
|
||||||
BETTER_AUTH_SECRET=R1MfeeeekXSNdE65hOhhr0Mt0KLwczYr
|
BETTER_AUTH_SECRET=R1MfeeeekXSNdE65hOhhr0Mt0KLwczYr
|
||||||
BETTER_AUTH_URL=http://localhost:3000
|
BETTER_AUTH_URL=http://localhost:3000
|
||||||
|
MAILTRAP_API_TOKEN=2c040e2e577dc48909d3206dd2d47fc6
|
||||||
|
MAIL_SANDBOX=true
|
||||||
1
apps/backend/.gitignore
vendored
1
apps/backend/.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
# deps
|
# deps
|
||||||
node_modules/
|
node_modules/
|
||||||
|
prisma.config.prod.ts
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
"better-auth": "^1.6.4",
|
"better-auth": "^1.6.4",
|
||||||
"dotenv": "^17.4.1",
|
"dotenv": "^17.4.1",
|
||||||
"hono": "4.12.10",
|
"hono": "4.12.10",
|
||||||
|
"mailtrap": "^4.5.1",
|
||||||
"nodemailer": "^8.0.5",
|
"nodemailer": "^8.0.5",
|
||||||
"pg": "^8.20.0",
|
"pg": "^8.20.0",
|
||||||
"pino": "10.3.1",
|
"pino": "10.3.1",
|
||||||
|
|||||||
@@ -1,29 +1,24 @@
|
|||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
|
import { MailtrapTransport } from 'mailtrap';
|
||||||
|
|
||||||
|
const TOKEN = Bun.env.MAILTRAP_API_TOKEN;
|
||||||
|
|
||||||
let cachedTransporter: ReturnType<typeof nodemailer.createTransport> | null = null;
|
let cachedTransporter: ReturnType<typeof nodemailer.createTransport> | null = null;
|
||||||
|
|
||||||
function getTransporter() {
|
function getTransporter() {
|
||||||
if (cachedTransporter) return cachedTransporter;
|
if (cachedTransporter) return cachedTransporter;
|
||||||
|
|
||||||
const smtpHost = Bun.env.SMTP_HOST;
|
if (!TOKEN) {
|
||||||
const smtpPort = Number(Bun.env.SMTP_PORT ?? 587);
|
throw new Error('Missing MAILTRAP_API_TOKEN env var.');
|
||||||
const smtpUser = Bun.env.SMTP_USER;
|
|
||||||
const smtpPass = Bun.env.SMTP_PASS;
|
|
||||||
|
|
||||||
if (!smtpHost || !smtpUser || !smtpPass) {
|
|
||||||
throw new Error('Missing SMTP env vars. Set SMTP_HOST, SMTP_PORT, SMTP_USER and SMTP_PASS.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedTransporter = nodemailer.createTransport({
|
cachedTransporter = nodemailer.createTransport(
|
||||||
host: smtpHost,
|
MailtrapTransport({
|
||||||
port: smtpPort,
|
token: TOKEN,
|
||||||
secure: smtpPort === 465,
|
sandbox: Bun.env.MAIL_SANDBOX === 'true',
|
||||||
auth: {
|
testInboxId: 1114587
|
||||||
user: smtpUser,
|
})
|
||||||
pass: smtpPass,
|
);
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return cachedTransporter;
|
return cachedTransporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
bun.lock
3
bun.lock
@@ -24,6 +24,7 @@
|
|||||||
"better-auth": "^1.6.4",
|
"better-auth": "^1.6.4",
|
||||||
"dotenv": "^17.4.1",
|
"dotenv": "^17.4.1",
|
||||||
"hono": "4.12.10",
|
"hono": "4.12.10",
|
||||||
|
"mailtrap": "^4.5.1",
|
||||||
"nodemailer": "^8.0.5",
|
"nodemailer": "^8.0.5",
|
||||||
"pg": "^8.20.0",
|
"pg": "^8.20.0",
|
||||||
"pino": "10.3.1",
|
"pino": "10.3.1",
|
||||||
@@ -1048,6 +1049,8 @@
|
|||||||
|
|
||||||
"magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
|
"magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
|
||||||
|
|
||||||
|
"mailtrap": ["mailtrap@4.5.1", "", { "dependencies": { "axios": ">=0.27", "qs": "^6.15.0" }, "peerDependencies": { "@types/nodemailer": "^6.4.9", "nodemailer": "^7.0.7" }, "optionalPeers": ["@types/nodemailer", "nodemailer"] }, "sha512-ABMvAk41q9iteM3Iga9ZaNrR/3RppGEPcYihihv6qnwvmFcE16mKcXSbuIRl3V5tRR5ZRQ4+BuUeZO2Y9xuxRA=="],
|
||||||
|
|
||||||
"math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="],
|
"math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="],
|
||||||
|
|
||||||
"media-typer": ["media-typer@1.1.0", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="],
|
"media-typer": ["media-typer@1.1.0", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="],
|
||||||
|
|||||||
Reference in New Issue
Block a user