diff --git a/src/mail.js b/src/mail.js index d2ff27671..cf2fe76cd 100644 --- a/src/mail.js +++ b/src/mail.js @@ -1024,9 +1024,11 @@ function sendTestMail(domain, to, callback) { getDomain(domain, function (error, result) { if (error) return callback(error); - mailer.sendTestMail(result.domain, to); + mailer.sendTestMail(result.domain, to, function (error) { + if (error) return callback(new MailError(MailError.EXTERNAL_ERROR, error.message)); - callback(); + callback(); + }); }); } diff --git a/src/mailer.js b/src/mailer.js index 19b6a61f9..fcda14a01 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -423,9 +423,10 @@ function oomEvent(mailTo, program, event) { }); } -function sendTestMail(domain, email) { +function sendTestMail(domain, email, callback) { assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof email, 'string'); + assert.strictEqual(typeof callback, 'function'); getMailConfig(function (error, mailConfig) { if (error) return debug('Error getting mail details:', error); @@ -437,6 +438,6 @@ function sendTestMail(domain, email) { text: render('test.ejs', { cloudronName: mailConfig.cloudronName, format: 'text'}) }; - sendMail(mailOptions); + sendMail(mailOptions, callback); }); } diff --git a/src/routes/mail.js b/src/routes/mail.js index 019209d59..0075bb5dd 100644 --- a/src/routes/mail.js +++ b/src/routes/mail.js @@ -204,6 +204,7 @@ function sendTestMail(req, res, next) { mail.sendTestMail(req.params.domain, req.body.to, function (error) { if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message)); + if (error && error.reason === MailError.EXTERNAL_ERROR) return next(new HttpError(424, error.message)); if (error) return next(new HttpError(500, error)); next(new HttpSuccess(202));