Refactor email transporter configuration in AuthService; update to support STARTTLS and TLS requirements based on environment variables, and adjust EMAIL_SECURE setting in production template for improved email security.
This commit is contained in:
@@ -42,7 +42,8 @@ FRONTEND_URL=https://stechuhr3.tsschulz.de
|
|||||||
# SMTP-Server Konfiguration
|
# SMTP-Server Konfiguration
|
||||||
EMAIL_HOST=smtp.1blu.de
|
EMAIL_HOST=smtp.1blu.de
|
||||||
EMAIL_PORT=587
|
EMAIL_PORT=587
|
||||||
EMAIL_SECURE=true
|
EMAIL_SECURE=false
|
||||||
|
EMAIL_REQUIRE_TLS=true
|
||||||
EMAIL_USER=e226079_0-kontakt
|
EMAIL_USER=e226079_0-kontakt
|
||||||
EMAIL_PASSWORD=aNN31bll3Na!
|
EMAIL_PASSWORD=aNN31bll3Na!
|
||||||
EMAIL_FROM=kontakt@tsschulz.de
|
EMAIL_FROM=kontakt@tsschulz.de
|
||||||
|
|||||||
@@ -22,16 +22,35 @@ class AuthService {
|
|||||||
*/
|
*/
|
||||||
initializeEmailTransporter() {
|
initializeEmailTransporter() {
|
||||||
if (process.env.EMAIL_HOST && process.env.EMAIL_USER && process.env.EMAIL_PASSWORD) {
|
if (process.env.EMAIL_HOST && process.env.EMAIL_USER && process.env.EMAIL_PASSWORD) {
|
||||||
this.emailTransporter = nodemailer.createTransport({
|
const port = parseInt(process.env.EMAIL_PORT) || 587;
|
||||||
|
const secure = process.env.EMAIL_SECURE === 'true';
|
||||||
|
|
||||||
|
// Port 587 = STARTTLS (secure: false)
|
||||||
|
// Port 465 = Direct SSL (secure: true)
|
||||||
|
const config = {
|
||||||
host: process.env.EMAIL_HOST,
|
host: process.env.EMAIL_HOST,
|
||||||
port: parseInt(process.env.EMAIL_PORT) || 587,
|
port: port,
|
||||||
secure: process.env.EMAIL_SECURE === 'true',
|
secure: secure, // true für Port 465, false für Port 587
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.EMAIL_USER,
|
user: process.env.EMAIL_USER,
|
||||||
pass: process.env.EMAIL_PASSWORD
|
pass: process.env.EMAIL_PASSWORD
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Für Port 587: STARTTLS aktivieren
|
||||||
|
if (port === 587 && !secure) {
|
||||||
|
config.requireTLS = process.env.EMAIL_REQUIRE_TLS !== 'false';
|
||||||
|
config.tls = {
|
||||||
|
rejectUnauthorized: process.env.NODE_ENV === 'production'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emailTransporter = nodemailer.createTransport(config);
|
||||||
|
|
||||||
console.log('✅ Email-Transporter konfiguriert');
|
console.log('✅ Email-Transporter konfiguriert');
|
||||||
|
console.log(' SMTP:', process.env.EMAIL_HOST + ':' + port);
|
||||||
|
console.log(' Secure:', secure);
|
||||||
|
console.log(' STARTTLS:', port === 587 && !secure ? 'aktiviert' : 'deaktiviert');
|
||||||
} else {
|
} else {
|
||||||
console.warn('⚠️ Email-Konfiguration fehlt - Passwort-Reset-E-Mails können nicht versendet werden');
|
console.warn('⚠️ Email-Konfiguration fehlt - Passwort-Reset-E-Mails können nicht versendet werden');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user