36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import nodemailer from 'nodemailer';
|
|
import config from '../config.js';
|
|
|
|
let transporter = null;
|
|
|
|
if (config.email.host) {
|
|
transporter = nodemailer.createTransport({
|
|
host: config.email.host,
|
|
port: config.email.port,
|
|
secure: config.email.secure,
|
|
auth: config.email.user
|
|
? { user: config.email.user, pass: config.email.pass }
|
|
: undefined,
|
|
});
|
|
}
|
|
|
|
export async function sendVerificationEmail(to, link) {
|
|
const subject = 'Verify your Fertig Classic Games account';
|
|
const text = `Welcome! Confirm your email by visiting:\n\n${link}\n\nThis link expires in ${config.email.verificationTtlHours} hour(s).`;
|
|
const html = `<p>Welcome!</p><p>Confirm your email by clicking the link below:</p><p><a href="${link}">${link}</a></p><p>This link expires in ${config.email.verificationTtlHours} hour(s).</p>`;
|
|
|
|
if (!transporter) {
|
|
console.log(`\n[mailer:dev] Verification link for ${to}:\n ${link}\n`);
|
|
return { delivered: false, devLogged: true };
|
|
}
|
|
|
|
await transporter.sendMail({
|
|
from: config.email.from,
|
|
to,
|
|
subject,
|
|
text,
|
|
html,
|
|
});
|
|
return { delivered: true, devLogged: false };
|
|
}
|