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
Some checks failed
Staging Build / build (push) Failing after 25s
This commit is contained in:
44
shop/utils/mail.ts
Normal file
44
shop/utils/mail.ts
Normal 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 Plain‑text 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;
|
||||
}
|
||||
Reference in New Issue
Block a user