From a5571fc59ac441898a7e1ec1d43e6a9f46f30c37 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 21 Sep 2022 15:58:04 +0100 Subject: [PATCH 1/3] CC and BCC interface --- .../src/automations/steps/sendSmtpEmail.js | 20 +++++++++++++++++-- .../server/src/utilities/workerRequests.js | 12 ++++++++++- .../src/api/controllers/global/email.js | 4 ++++ .../worker/src/api/routes/global/email.js | 8 +++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/server/src/automations/steps/sendSmtpEmail.js b/packages/server/src/automations/steps/sendSmtpEmail.js index 71e544a00d..423363701b 100644 --- a/packages/server/src/automations/steps/sendSmtpEmail.js +++ b/packages/server/src/automations/steps/sendSmtpEmail.js @@ -21,6 +21,14 @@ exports.definition = { type: "string", title: "Send From", }, + cc: { + type: "string", + title: "CC", + }, + bcc: { + type: "string", + title: "BCC", + }, subject: { type: "string", title: "Email Subject", @@ -49,13 +57,21 @@ exports.definition = { } exports.run = async function ({ inputs }) { - let { to, from, subject, contents } = inputs + let { to, from, subject, contents, cc, bcc } = inputs if (!contents) { contents = "

No content

" } to = to || undefined try { - let response = await sendSmtpEmail(to, from, subject, contents, true) + let response = await sendSmtpEmail( + to, + from, + subject, + contents, + cc, + bcc, + true + ) return { success: true, response, diff --git a/packages/server/src/utilities/workerRequests.js b/packages/server/src/utilities/workerRequests.js index e08ad147d1..53f13b6e02 100644 --- a/packages/server/src/utilities/workerRequests.js +++ b/packages/server/src/utilities/workerRequests.js @@ -54,7 +54,15 @@ async function checkResponse(response, errorMsg, { ctx } = {}) { exports.request = request // have to pass in the tenant ID as this could be coming from an automation -exports.sendSmtpEmail = async (to, from, subject, contents, automation) => { +exports.sendSmtpEmail = async ( + to, + from, + subject, + contents, + cc, + bcc, + automation +) => { // tenant ID will be set in header const response = await fetch( checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`), @@ -65,6 +73,8 @@ exports.sendSmtpEmail = async (to, from, subject, contents, automation) => { from, contents, subject, + cc, + bcc, purpose: "custom", automation, }, diff --git a/packages/worker/src/api/controllers/global/email.js b/packages/worker/src/api/controllers/global/email.js index 125376cdc2..85e39be0da 100644 --- a/packages/worker/src/api/controllers/global/email.js +++ b/packages/worker/src/api/controllers/global/email.js @@ -10,6 +10,8 @@ exports.sendEmail = async ctx => { contents, from, subject, + cc, + bcc, automation, } = ctx.request.body let user @@ -23,6 +25,8 @@ exports.sendEmail = async ctx => { contents, from, subject, + cc, + bcc, automation, }) ctx.body = { diff --git a/packages/worker/src/api/routes/global/email.js b/packages/worker/src/api/routes/global/email.js index 940bb4d134..db3b4db63b 100644 --- a/packages/worker/src/api/routes/global/email.js +++ b/packages/worker/src/api/routes/global/email.js @@ -12,7 +12,13 @@ function buildEmailSendValidation() { return joiValidator.body(Joi.object({ email: Joi.string().email({ multiple: true, - }), + }), + cc: Joi.string().email({ + multiple: true, + }), + bcc: Joi.string().email({ + multiple: true, + }), purpose: Joi.string().valid(...Object.values(EmailTemplatePurpose)), workspaceId: Joi.string().allow("", null), from: Joi.string().allow("", null), From a0a87e0b1d141284f1ac988db62accd8200ce8fd Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 21 Sep 2022 16:07:54 +0100 Subject: [PATCH 2/3] Send CC and BCC --- packages/worker/src/utilities/email.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 06b1ea851c..66f78bb543 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -174,7 +174,7 @@ exports.isEmailConfigured = async (workspaceId = null) => { exports.sendEmail = async ( email, purpose, - { workspaceId, user, from, contents, subject, info, automation } = {} + { workspaceId, user, from, contents, subject, info, cc, bcc, automation } = {} ) => { const db = getGlobalDB() let config = (await getSmtpConfiguration(db, workspaceId, automation)) || {} @@ -197,6 +197,8 @@ exports.sendEmail = async ( message = { ...message, to: email, + cc: cc, + bcc: bcc, } if (subject || config.subject) { From e40349a05f262b140c2211cc407b86adf815a998 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 22 Sep 2022 08:09:54 +0100 Subject: [PATCH 3/3] Allow null values for cc, bcc --- packages/worker/src/api/routes/global/email.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/api/routes/global/email.js b/packages/worker/src/api/routes/global/email.js index db3b4db63b..d545c10ede 100644 --- a/packages/worker/src/api/routes/global/email.js +++ b/packages/worker/src/api/routes/global/email.js @@ -15,10 +15,10 @@ function buildEmailSendValidation() { }), cc: Joi.string().email({ multiple: true, - }), + }).allow("", null), bcc: Joi.string().email({ multiple: true, - }), + }).allow("", null), purpose: Joi.string().valid(...Object.values(EmailTemplatePurpose)), workspaceId: Joi.string().allow("", null), from: Joi.string().allow("", null),