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:
@@ -24,7 +24,7 @@ const SESSIONS_FILE = getDataPath('sessions.json')
|
||||
|
||||
// Get encryption key from environment
|
||||
function getEncryptionKey() {
|
||||
return process.env.ENCRYPTION_KEY || 'default-key-change-in-production'
|
||||
return process.env.ENCRYPTION_KEY || 'local_development_encryption_key_change_in_production'
|
||||
}
|
||||
|
||||
// Check if data is encrypted by trying to parse as JSON first
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const MEMBERS_FILE = getDataPath('members.json')
|
||||
|
||||
// Get encryption key from environment or config
|
||||
function getEncryptionKey() {
|
||||
return process.env.ENCRYPTION_KEY || 'default-key-change-in-production'
|
||||
return process.env.ENCRYPTION_KEY || 'local_development_encryption_key_change_in_production'
|
||||
}
|
||||
|
||||
// Check if data is encrypted by trying to parse as JSON first
|
||||
|
||||
Reference in New Issue
Block a user