Merge pull request #2271 from catilgan-nextension/fix/nodemailer_relay
Enabling SMTP Relay with Nodemailer
This commit is contained in:
6 files changed
+37
-1
No files matched your search
@@ -122,6 +122,15 @@ const SettingsEmail = ({
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
<Box>
|
||||
<Typography>{t("systemEmailConnectionHost")}</Typography>
|
||||
<TextInput
|
||||
name="systemEmailConnectionHost"
|
||||
placeholder="bluewavelabs.ca"
|
||||
value={settingsData?.settings?.systemEmailConnectionHost ?? ""}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<Button
|
||||
variant="contained"
|
||||
|
||||
@@ -278,6 +278,7 @@ const settingsValidation = joi.object({
|
||||
systemEmailAddress: joi.string().allow(""),
|
||||
systemEmailPassword: joi.string().allow(""),
|
||||
systemEmailUser: joi.string().allow(""),
|
||||
systemEmailConnectionHost: joi.string().allow(""),
|
||||
});
|
||||
|
||||
const dayjsValidator = (value, helpers) => {
|
||||
@@ -307,6 +308,7 @@ const advancedSettingsValidation = joi.object({
|
||||
systemEmailPort: joi.number().allow(null, ""),
|
||||
systemEmailAddress: joi.string().allow(""),
|
||||
systemEmailPassword: joi.string().allow(""),
|
||||
systemEmailConnectionHost: joi.string().allow(""),
|
||||
jwtTTLNum: joi.number().messages({
|
||||
"number.base": "JWT TTL is required.",
|
||||
}),
|
||||
|
||||
@@ -120,6 +120,7 @@
|
||||
"settingsEmailPassword": "Email password",
|
||||
"settingsEmailUser": "Email user",
|
||||
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
|
||||
"systemEmailConnectionHost":"Email connection host",
|
||||
"backendUnreachable": "Server Connection Error",
|
||||
"backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.",
|
||||
"backendUnreachableError": "Cannot connect to the server. Please try again later.",
|
||||
|
||||
@@ -28,6 +28,10 @@ const AppSettingsSchema = mongoose.Schema(
|
||||
systemEmailUser: {
|
||||
type: String,
|
||||
},
|
||||
systemEmailConnectionHost: {
|
||||
type: String,
|
||||
default: "localhost",
|
||||
},
|
||||
singleton: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
|
||||
@@ -11,6 +11,7 @@ const SERVICE_NAME = "EmailService";
|
||||
*/
|
||||
class EmailService {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the EmailService, initializing template loaders and the email transporter.
|
||||
* @param {Object} settingsService - The settings service to get email configuration.
|
||||
@@ -96,9 +97,10 @@ class EmailService {
|
||||
systemEmailUser,
|
||||
systemEmailAddress,
|
||||
systemEmailPassword,
|
||||
systemEmailConnectionHost,
|
||||
} = await this.settingsService.getDBSettings();
|
||||
|
||||
const emailConfig = {
|
||||
const baseEmailConfig = {
|
||||
host: systemEmailHost,
|
||||
port: systemEmailPort,
|
||||
secure: true,
|
||||
@@ -109,6 +111,22 @@ class EmailService {
|
||||
connectionTimeout: 5000,
|
||||
};
|
||||
|
||||
const isSmtps = Number(systemEmailPort) === 465;
|
||||
|
||||
const emailConfig = !isSmtps
|
||||
? {
|
||||
...baseEmailConfig,
|
||||
name: systemEmailConnectionHost || "localhost",
|
||||
secure: false,
|
||||
pool: true,
|
||||
tls: { rejectUnauthorized: false },
|
||||
}
|
||||
: baseEmailConfig;
|
||||
|
||||
if (!isSmtps) {
|
||||
delete emailConfig.auth;
|
||||
}
|
||||
|
||||
this.transporter = this.nodemailer.createTransport(emailConfig);
|
||||
|
||||
const buildHtml = async (template, context) => {
|
||||
@@ -149,4 +167,5 @@ class EmailService {
|
||||
return info?.messageId;
|
||||
};
|
||||
}
|
||||
|
||||
export default EmailService;
|
||||
@@ -432,6 +432,7 @@ const updateAppSettingsBodyValidation = joi.object({
|
||||
systemEmailAddress: joi.string().allow(""),
|
||||
systemEmailPassword: joi.string().allow(""),
|
||||
systemEmailUser: joi.string().allow(""),
|
||||
systemEmailConnectionHost: joi.string().allow(""),
|
||||
});
|
||||
|
||||
//****************************************
|
||||
|
||||
Reference in new issue
Block a user