Updating SMTP config to show better errors.

This commit is contained in:
mike12345567 2021-06-09 15:45:54 +01:00
parent ad45781228
commit 22431a4ea2
4 changed files with 23 additions and 18 deletions

View File

@ -38,17 +38,21 @@
let loading let loading
async function saveSmtp() { async function saveSmtp() {
try {
// Save your SMTP config // Save your SMTP config
const response = await api.post(`/api/admin/configs`, smtpConfig) const response = await api.post(`/api/admin/configs`, smtpConfig)
if (response.status !== 200) {
const error = await response.text()
let message = error
try {
message = JSON.parse(error).message
} catch (err) {}
notifications.error(`Failed to save email settings, reason: ${message}`)
} else {
const json = await response.json() const json = await response.json()
if (response.status !== 200) throw new Error(json.message)
smtpConfig._rev = json._rev smtpConfig._rev = json._rev
smtpConfig._id = json._id smtpConfig._id = json._id
notifications.success(`Settings saved.`) notifications.success(`Settings saved.`)
} catch (err) {
notifications.error(`Failed to save email settings. ${err}`)
} }
} }

View File

@ -27,12 +27,16 @@ exports.save = async function (ctx) {
}) })
} }
try {
// verify the configuration // verify the configuration
switch (type) { switch (type) {
case Configs.SMTP: case Configs.SMTP:
await email.verifyConfig(config) await email.verifyConfig(config)
break break
} }
} catch (err) {
ctx.throw(400, err)
}
try { try {
const response = await db.put(ctx.request.body) const response = await db.put(ctx.request.body)
@ -42,7 +46,7 @@ exports.save = async function (ctx) {
_rev: response.rev, _rev: response.rev,
} }
} catch (err) { } catch (err) {
ctx.throw(err.status, err) ctx.throw(400, err)
} }
} }

View File

@ -14,7 +14,6 @@ function smtpValidation() {
host: Joi.string().required(), host: Joi.string().required(),
from: Joi.string().email().required(), from: Joi.string().email().required(),
secure: Joi.boolean().optional(), secure: Joi.boolean().optional(),
selfSigned: Joi.boolean().optional(),
auth: Joi.object({ auth: Joi.object({
type: Joi.string().valid("login", "oauth2", null), type: Joi.string().valid("login", "oauth2", null),
user: Joi.string().required(), user: Joi.string().required(),

View File

@ -27,11 +27,9 @@ function createSMTPTransport(config) {
secure: config.secure || false, secure: config.secure || false,
auth: config.auth, auth: config.auth,
} }
if (config.selfSigned) {
options.tls = { options.tls = {
rejectUnauthorized: false, rejectUnauthorized: false,
} }
}
} else { } else {
options = { options = {
port: 587, port: 587,