Add SMTP mail utility, admin settings page, and API routes for SMTP configuration and test email
Some checks failed
Staging Build / build (push) Failing after 25s

This commit is contained in:
DanielS
2026-06-23 00:17:41 +02:00
parent 4b9c289ec4
commit 4402d4ec64
6 changed files with 318 additions and 4 deletions

44
shop/utils/mail.ts Normal file
View File

@@ -0,0 +1,44 @@
// utils/mail.ts simple wrapper around nodemailer
import nodemailer from 'nodemailer';
// Load SMTP configuration from environment variables
const smtpConfig = {
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: process.env.SMTP_SECURE === 'true' || process.env.SMTP_SECURE === '1', // true for 465, false for other ports
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
};
// Create a reusable transporter. If any required var is missing, nodemailer will throw on send.
const transporter = nodemailer.createTransport(smtpConfig);
/**
* Send an email.
* @param to Recipient address
* @param subject Subject line
* @param text Plaintext body
* @param html Optional HTML body
*/
export async function sendMail({
to,
subject,
text,
html,
}: {
to: string;
subject: string;
text: string;
html?: string;
}) {
const info = await transporter.sendMail({
from: smtpConfig.auth.user,
to,
subject,
text,
html,
});
return info;
}