fix: Support Exchange servers without authentication
- Make email authentication optional in transporter config - Only add auth object if both username and password are provided - Update initialization to only require SMTP_HOST - Add logging to show whether auth is enabled - Update documentation with no-auth configuration examples - Fix "Unrecognized authentication type" error for open relays Exchange servers configured as internal relays often don't require authentication. This fix allows using them by leaving SMTP_USER and SMTP_PASS empty in the .env file. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,23 +10,19 @@ class ReportService {
|
||||
this.transporter = null;
|
||||
this.scheduledTask = null;
|
||||
|
||||
if (config.email.host && config.email.auth.user) {
|
||||
if (config.email.host) {
|
||||
this.initializeMailer();
|
||||
this.setupSchedule();
|
||||
} else {
|
||||
logger.warn('Email configuration missing. Report scheduling disabled.');
|
||||
logger.warn('Email host not configured. Report scheduling disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
initializeMailer() {
|
||||
this.transporter = nodemailer.createTransport({
|
||||
const transportConfig = {
|
||||
host: config.email.host,
|
||||
port: config.email.port,
|
||||
secure: config.email.secure,
|
||||
auth: {
|
||||
user: config.email.auth.user,
|
||||
pass: config.email.auth.pass,
|
||||
},
|
||||
// For Exchange Server on port 25 without TLS
|
||||
tls: {
|
||||
rejectUnauthorized: false, // Accept self-signed certificates
|
||||
@@ -36,7 +32,20 @@ class ReportService {
|
||||
// Disable STARTTLS for port 25 if not using secure
|
||||
requireTLS: config.email.secure,
|
||||
ignoreTLS: config.email.port === 25 && !config.email.secure,
|
||||
});
|
||||
};
|
||||
|
||||
// Only add auth if username and password are provided
|
||||
if (config.email.auth.user && config.email.auth.pass) {
|
||||
transportConfig.auth = {
|
||||
user: config.email.auth.user,
|
||||
pass: config.email.auth.pass,
|
||||
};
|
||||
logger.info('Email configured with authentication');
|
||||
} else {
|
||||
logger.info('Email configured without authentication (open relay)');
|
||||
}
|
||||
|
||||
this.transporter = nodemailer.createTransport(transportConfig);
|
||||
|
||||
// Verify connection
|
||||
this.transporter.verify((error) => {
|
||||
|
||||
Reference in New Issue
Block a user