verify transport before sending email

This commit is contained in:
Alex Holliday committed 2025-06-25 09:35:41 +08:00
1 parent 915d2e06ae
commit 4cc3765e0d
3 files changed
+21 -5

No files matched your search

+6 -1
View File
@@ -77,11 +77,16 @@ class InviteController {
name: firstname, name: firstname,
link: `${clientHost}/register/${inviteToken.token}`, link: `${clientHost}/register/${inviteToken.token}`,
}); });
await this.emailService.sendEmail( const result = await this.emailService.sendEmail(
req.body.email, req.body.email,
"Welcome to Uptime Monitor", "Welcome to Uptime Monitor",
html html
); );
if (!result) {
return res.error({
msg: "Failed to send invite e-mail... Please verify your settings.",
});
}
} catch (error) { } catch (error) {
logger.warn({ logger.warn({
message: error.message, message: error.message,
+11
View File
@@ -137,6 +137,17 @@ class EmailService {
}; };
this.transporter = this.nodemailer.createTransport(emailConfig); this.transporter = this.nodemailer.createTransport(emailConfig);
try {
await this.transporter.verify();
} catch (error) {
this.logger.warn({
message: "Email transporter verification failed",
service: SERVICE_NAME,
method: "verifyTransporter",
});
return false;
}
try { try {
const info = await this.transporter.sendMail({ const info = await this.transporter.sendMail({
to: to, to: to,
+4 -4
View File
@@ -76,7 +76,7 @@ class Logger {
info(config) { info(config) {
const logEntry = this.buildLogEntry("info", config); const logEntry = this.buildLogEntry("info", config);
this.cacheLog(logEntry); this.cacheLog(logEntry);
this.logger.info(config.message, logEntry); this.logger.info(logEntry);
} }
/** /**
@@ -90,7 +90,7 @@ class Logger {
warn(config) { warn(config) {
const logEntry = this.buildLogEntry("warn", config); const logEntry = this.buildLogEntry("warn", config);
this.cacheLog(logEntry); this.cacheLog(logEntry);
this.logger.warn(config.message, logEntry); this.logger.warn(logEntry);
} }
/** /**
@@ -104,7 +104,7 @@ class Logger {
error(config) { error(config) {
const logEntry = this.buildLogEntry("error", config); const logEntry = this.buildLogEntry("error", config);
this.cacheLog(logEntry); this.cacheLog(logEntry);
this.logger.error(config.message, logEntry); this.logger.error(logEntry);
} }
/** /**
* Logs a debug message. * Logs a debug message.
@@ -117,7 +117,7 @@ class Logger {
debug(config) { debug(config) {
const logEntry = this.buildLogEntry("debug", config); const logEntry = this.buildLogEntry("debug", config);
this.cacheLog(logEntry); this.cacheLog(logEntry);
this.logger.debug(config.message, logEntry); this.logger.debug(logEntry);
} }
cacheLog(entry) { cacheLog(entry) {