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:
@@ -22,13 +22,23 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
// SMTP-Konfiguration (hier können Sie Ihre SMTP-Daten eintragen)
|
||||
const smtpUser = process.env.SMTP_USER || 'j.dichmann@gmx.de'
|
||||
const smtpPass = process.env.SMTP_PASS || process.env.EMAIL_PASSWORD
|
||||
|
||||
if (!smtpUser || !smtpPass) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'SMTP-Credentials fehlen! Bitte setzen Sie SMTP_USER und SMTP_PASS in der .env Datei.'
|
||||
})
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST || 'smtp.gmail.com',
|
||||
port: process.env.SMTP_PORT || 587,
|
||||
secure: false, // true für 465, false für andere Ports
|
||||
auth: {
|
||||
user: process.env.SMTP_USER || 'j.dichmann@gmx.de',
|
||||
pass: process.env.SMTP_PASS || process.env.EMAIL_PASSWORD
|
||||
user: smtpUser,
|
||||
pass: smtpPass
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user