Commit 7555b5bb authored by Yannis Barlas's avatar Yannis Barlas
Browse files

improvement(component-send-email): mailer config should be optional for servers

parent 6f5b7290
Pipeline #17583 failed with stages
in 66 minutes and 5 seconds
......@@ -2,20 +2,27 @@ const logger = require('@pubsweet/logger')
const nodemailer = require('nodemailer')
const config = require('config')
let mailerConfig = {}
try {
let mailerConfig
if (config.has('mailer.path')) {
mailerConfig = require(config.get('mailer.path'))
} catch (err) {
logger.error(
'Mailer: The configuration is either invalid or missing. Check here: ' +
'https://gitlab.coko.foundation/pubsweet/pubsweet/tree/master/packages/components/server/component-send-email',
)
throw err
} else if (config.has('mailer.transport')) {
mailerConfig = config.get('mailer.transport')
}
const docsUrl =
'https://gitlab.coko.foundation/pubsweet/pubsweet/tree/master/packages/components/server/component-send-email'
module.exports = {
send: mailData => {
if (!mailerConfig || !mailerConfig.transport) {
throw new Error(
`Mailer: The configuration is either invalid or missing. Check here: ${docsUrl}`,
)
}
const transporter = nodemailer.createTransport(mailerConfig.transport)
return transporter
.sendMail(mailData)
.then(info => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment