Skip to content

Commit 7450fa5

Browse files
author
Sachin Maheshwari
committed
'from' and multiple 'categories' support.
1 parent b6f7b96 commit 7450fa5

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ 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+
20+
return sgMail.send({
1421
to,
1522
templateId,
1623
substitutions,
17-
from: config.EMAIL_FROM,
24+
from,
1825
substitutionWrappers: ['{{', '}}'],
1926
replyTo,
27+
categories,
2028
});
21-
29+
}
2230
module.exports = {
2331
sendEmail,
2432
}

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)