Skip to content

supporting cc, bcc, from and categories fields are optional. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions connect/connectEmailServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
20 changes: 16 additions & 4 deletions connect/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
7 changes: 4 additions & 3 deletions docs/swagger_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/emailServiceTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down