Add dotenv package for environment variable management and refactor SMTP credential handling in email services. Enhance error handling for missing SMTP credentials across various API endpoints to improve reliability and maintainability.

This commit is contained in:
Torsten Schulz (local)
2025-12-18 12:19:23 +01:00
parent 1a093340ab
commit 680629e1f8
12 changed files with 492 additions and 95 deletions

View File

@@ -80,13 +80,23 @@ function getEmailRecipients(data, config) {
* @returns {Object} Nodemailer transporter
*/
function createTransporter() {
const smtpUser = process.env.SMTP_USER
const smtpPass = process.env.SMTP_PASS
if (!smtpUser || !smtpPass) {
throw new Error(
'SMTP-Credentials fehlen! Bitte setzen Sie SMTP_USER und SMTP_PASS in der .env Datei.\n' +
`Aktuell: SMTP_USER=${smtpUser ? 'gesetzt' : 'FEHLT'}, SMTP_PASS=${smtpPass ? 'gesetzt' : 'FEHLT'}`
)
}
return nodemailer.createTransporter({
host: process.env.SMTP_HOST || 'localhost',
port: parseInt(process.env.SMTP_PORT) || 587,
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
user: smtpUser,
pass: smtpPass
}
})
}