diff --git a/connect/connectEmailServer.js b/connect/connectEmailServer.js index 30bb293..5856b54 100644 --- a/connect/connectEmailServer.js +++ b/connect/connectEmailServer.js @@ -26,8 +26,7 @@ const handler = (topic, message, callback) => { return callback(null, { success: false, error: `Template not found for topic ${topic}` }); } - const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; - service.sendEmail(templateId, message.recipients, message.data, replyTo).then(() => { + service.sendEmail(templateId, message).then(() => { callback(null, { success: true }); }).catch((err) => { callback(null, { success: false, error: err }); diff --git a/connect/service.js b/connect/service.js index 10c860b..4750b9b 100644 --- a/connect/service.js +++ b/connect/service.js @@ -9,16 +9,28 @@ const config = require('config'); // set api key for SendGrid email client sgMail.setApiKey(config.SENDGRID_API_KEY); -const sendEmail = (templateId, to, substitutions, replyTo) => // send email - sgMail.send({ +const sendEmail = (templateId, message) => { // send email + + const from = message.from ? message.from : config.EMAIL_FROM; + const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; + const substitutions = message.data ; + const categories = message.categories ? message.categories: []; + const to = message.recipients; + const cc = message.cc ? message.cc : []; + const bcc = message.bcc ? message.bcc : []; + + return sgMail.send({ to, templateId, substitutions, - from: config.EMAIL_FROM, + from, substitutionWrappers: ['{{', '}}'], replyTo, + categories, + cc, + bcc, }); - +} module.exports = { sendEmail, } diff --git a/docs/swagger_api.yaml b/docs/swagger_api.yaml index 4838664..1a8c8a5 100644 --- a/docs/swagger_api.yaml +++ b/docs/swagger_api.yaml @@ -3,9 +3,10 @@ info: title: "TOPCODER EMAIL SERIES - EMAIL SERVER" description: "TOPCODER EMAIL SERIES - EMAIL SERVER" version: "1.0.0" -host: "localhost:4001" +host: "localhost:6100" +basePath : "/v5/email" schemes: -- "http" +- "https" securityDefinitions: jwt: type: apiKey @@ -14,7 +15,7 @@ securityDefinitions: description: JWT Authentication. Provide API Key in the form 'Bearer <token>'. paths: - /templates/eventType/{name}: + /templates/{name}: get: description: get email template placholders name diff --git a/test/emailServiceTest.js b/test/emailServiceTest.js index 2b25a0f..68d52a7 100644 --- a/test/emailServiceTest.js +++ b/test/emailServiceTest.js @@ -24,8 +24,7 @@ const defaultHandler = (topic, message, callback) => { } // send email - const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; - service.sendEmail(templateId, message.recipients, message.data).then(() => { + service.sendEmail(templateId, message).then(() => { callback(null, { success: true }); finish(null); }).catch((err) => {