verify transport before sending email

This commit is contained in:
Alex Holliday
2025-06-25 09:35:41 +08:00
parent 915d2e06ae
commit 4cc3765e0d
3 changed files with 21 additions and 5 deletions
+6 -1
View File
@@ -77,11 +77,16 @@ class InviteController {
name: firstname,
link: `${clientHost}/register/${inviteToken.token}`,
});
await this.emailService.sendEmail(
const result = await this.emailService.sendEmail(
req.body.email,
"Welcome to Uptime Monitor",
html
);
if (!result) {
return res.error({
msg: "Failed to send invite e-mail... Please verify your settings.",
});
}
} catch (error) {
logger.warn({
message: error.message,
+11
View File
@@ -137,6 +137,17 @@ class EmailService {
};
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 {
const info = await this.transporter.sendMail({
to: to,
+4 -4
View File
@@ -76,7 +76,7 @@ class Logger {
info(config) {
const logEntry = this.buildLogEntry("info", config);
this.cacheLog(logEntry);
this.logger.info(config.message, logEntry);
this.logger.info(logEntry);
}
/**
@@ -90,7 +90,7 @@ class Logger {
warn(config) {
const logEntry = this.buildLogEntry("warn", config);
this.cacheLog(logEntry);
this.logger.warn(config.message, logEntry);
this.logger.warn(logEntry);
}
/**
@@ -104,7 +104,7 @@ class Logger {
error(config) {
const logEntry = this.buildLogEntry("error", config);
this.cacheLog(logEntry);
this.logger.error(config.message, logEntry);
this.logger.error(logEntry);
}
/**
* Logs a debug message.
@@ -117,7 +117,7 @@ class Logger {
debug(config) {
const logEntry = this.buildLogEntry("debug", config);
this.cacheLog(logEntry);
this.logger.debug(config.message, logEntry);
this.logger.debug(logEntry);
}
cacheLog(entry) {