Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.

Commit fac91de

Browse files
committed
Update routing middleware to support multiple to, cc, bcc in send action
1 parent d441cc6 commit fac91de

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: lib/routing.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const CONTENT_TYPES = {
1212
text: 'text/plain'
1313
};
1414

15+
const arrayOrString = (str) => {
16+
return Array.isArray(str) ? str : str.split(',');
17+
};
18+
1519
Routing = (template, settings, render, compile) => {
1620
check(template.name, String);
1721
check(template.route.path, String);
@@ -22,7 +26,7 @@ Routing = (template, settings, render, compile) => {
2226
const previewAction = (type) => {
2327
check(type, Match.OneOf('html', 'text'));
2428

25-
return (req, res, params, template) => {
29+
return (req, res, params, _) => {
2630
let data = null;
2731

2832
try {
@@ -71,7 +75,7 @@ Routing = (template, settings, render, compile) => {
7175
};
7276
};
7377

74-
const sendAction = (req, res, params, template) => {
78+
const sendAction = (req, res, params, _) => {
7579
const {to = settings.testEmail, cc, bcc} = params.query;
7680

7781
Utils.Logger.info(`Sending ${template.name}…`);
@@ -87,18 +91,18 @@ Routing = (template, settings, render, compile) => {
8791
}
8892

8993
const options = {
90-
to,
94+
to: arrayOrString(to),
9195
data,
9296
template: template.name,
9397
subject: '[TEST] ' + template.name
9498
};
9599

96100
if (cc) {
97-
options.cc = cc;
101+
options.cc = arrayOrString(cc);
98102
}
99103

100104
if (bcc) {
101-
options.bcc = bcc;
105+
options.bcc = arrayOrString(bcc);
102106
}
103107

104108
const result = Mailer.send(options);

0 commit comments

Comments
 (0)