feat: add SMTP mailer for price-change notifications
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
function createTransport(env = process.env) {
|
||||
return nodemailer.createTransport({
|
||||
host: env.SMTP_HOST,
|
||||
port: Number(env.SMTP_PORT || 587),
|
||||
secure: Number(env.SMTP_PORT) === 465,
|
||||
auth: env.SMTP_USER ? { user: env.SMTP_USER, pass: env.SMTP_PASS } : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
function formatPrice(value) {
|
||||
return value.toFixed(2).replace('.', ',');
|
||||
}
|
||||
|
||||
async function sendPriceChangeEmail(transport, { from, to, name, url, oldPrice, newPrice }) {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to,
|
||||
subject: `Prijs gewijzigd: ${name}`,
|
||||
text: [
|
||||
`De prijs van "${name}" is gewijzigd.`,
|
||||
`Oude prijs: €${formatPrice(oldPrice)}`,
|
||||
`Nieuwe prijs: €${formatPrice(newPrice)}`,
|
||||
`Link: ${url}`,
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { createTransport, sendPriceChangeEmail, formatPrice };
|
||||
Reference in New Issue
Block a user