Skip to content

Commit 5051b36

Browse files
author
sachin-maheshwari
authored
Merge pull request #15 from topcoder-platform/dev
supporting cc, bcc, from and categories fields are optional.
2 parents b0cfe04 + fd50c9e commit 5051b36

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

connect/connectEmailServer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ const handler = (topic, message, callback) => {
2626
return callback(null, { success: false, error: `Template not found for topic ${topic}` });
2727
}
2828

29-
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM;
30-
service.sendEmail(templateId, message.recipients, message.data, replyTo).then(() => {
29+
service.sendEmail(templateId, message).then(() => {
3130
callback(null, { success: true });
3231
}).catch((err) => {
3332
callback(null, { success: false, error: err });

connect/service.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,28 @@ const config = require('config');
99
// set api key for SendGrid email client
1010
sgMail.setApiKey(config.SENDGRID_API_KEY);
1111

12-
const sendEmail = (templateId, to, substitutions, replyTo) => // send email
13-
sgMail.send({
12+
const sendEmail = (templateId, message) => { // send email
13+
14+
const from = message.from ? message.from : config.EMAIL_FROM;
15+
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM;
16+
const substitutions = message.data ;
17+
const categories = message.categories ? message.categories: [];
18+
const to = message.recipients;
19+
const cc = message.cc ? message.cc : [];
20+
const bcc = message.bcc ? message.bcc : [];
21+
22+
return sgMail.send({
1423
to,
1524
templateId,
1625
substitutions,
17-
from: config.EMAIL_FROM,
26+
from,
1827
substitutionWrappers: ['{{', '}}'],
1928
replyTo,
29+
categories,
30+
cc,
31+
bcc,
2032
});
21-
33+
}
2234
module.exports = {
2335
sendEmail,
2436
}

docs/swagger_api.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ info:
33
title: "TOPCODER EMAIL SERIES - EMAIL SERVER"
44
description: "TOPCODER EMAIL SERIES - EMAIL SERVER"
55
version: "1.0.0"
6-
host: "localhost:4001"
6+
host: "localhost:6100"
7+
basePath : "/v5/email"
78
schemes:
8-
- "http"
9+
- "https"
910
securityDefinitions:
1011
jwt:
1112
type: apiKey
@@ -14,7 +15,7 @@ securityDefinitions:
1415
description: JWT Authentication. Provide API Key in the form 'Bearer <token>'.
1516

1617
paths:
17-
/templates/eventType/{name}:
18+
/templates/{name}:
1819
get:
1920
description:
2021
get email template placholders name

test/emailServiceTest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ const defaultHandler = (topic, message, callback) => {
2424
}
2525

2626
// send email
27-
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM;
28-
service.sendEmail(templateId, message.recipients, message.data).then(() => {
27+
service.sendEmail(templateId, message).then(() => {
2928
callback(null, { success: true });
3029
finish(null);
3130
}).catch((err) => {

0 commit comments

Comments
 (0)