36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
// mailer.js — sends mail through the practice's own SMTP account (their normal
|
|
// mailbox + an app password, entered once in Einstellungen). No third-party email
|
|
// service involved; credentials are stored in the shared data folder's database,
|
|
// same trust model as the folder path itself.
|
|
"use strict";
|
|
|
|
const nodemailer = require("nodemailer");
|
|
|
|
function buildTransport(smtp) {
|
|
return nodemailer.createTransport({
|
|
host: smtp.host,
|
|
port: Number(smtp.port) || 587,
|
|
secure: !!smtp.secure,
|
|
auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined,
|
|
});
|
|
}
|
|
|
|
async function verifySmtp(smtp) {
|
|
const transporter = buildTransport(smtp);
|
|
await transporter.verify();
|
|
}
|
|
|
|
async function sendMail(smtp, { to, subject, text, attachments }) {
|
|
const transporter = buildTransport(smtp);
|
|
const fromAddress = smtp.fromEmail || smtp.user;
|
|
await transporter.sendMail({
|
|
from: smtp.fromName ? `"${smtp.fromName}" <${fromAddress}>` : fromAddress,
|
|
to,
|
|
subject,
|
|
text,
|
|
attachments,
|
|
});
|
|
}
|
|
|
|
module.exports = { verifySmtp, sendMail };
|