1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Merge pull request #7881 from Budibase/feature/email-cc

Add CC and BCC (with multiple email support) to Send Email automation action step
This commit is contained in:
Martin McKeaveney 2022-09-25 13:40:33 +01:00 committed by GitHub
commit c309d25b16
5 changed files with 43 additions and 5 deletions

View file

@ -21,6 +21,14 @@ exports.definition = {
type: "string", type: "string",
title: "Send From", title: "Send From",
}, },
cc: {
type: "string",
title: "CC",
},
bcc: {
type: "string",
title: "BCC",
},
subject: { subject: {
type: "string", type: "string",
title: "Email Subject", title: "Email Subject",
@ -49,13 +57,21 @@ exports.definition = {
} }
exports.run = async function ({ inputs }) { exports.run = async function ({ inputs }) {
let { to, from, subject, contents } = inputs let { to, from, subject, contents, cc, bcc } = inputs
if (!contents) { if (!contents) {
contents = "<h1>No content</h1>" contents = "<h1>No content</h1>"
} }
to = to || undefined to = to || undefined
try { try {
let response = await sendSmtpEmail(to, from, subject, contents, true) let response = await sendSmtpEmail(
to,
from,
subject,
contents,
cc,
bcc,
true
)
return { return {
success: true, success: true,
response, response,

View file

@ -54,7 +54,15 @@ async function checkResponse(response, errorMsg, { ctx } = {}) {
exports.request = request exports.request = request
// have to pass in the tenant ID as this could be coming from an automation // 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 // tenant ID will be set in header
const response = await fetch( const response = await fetch(
checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`), checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`),
@ -65,6 +73,8 @@ exports.sendSmtpEmail = async (to, from, subject, contents, automation) => {
from, from,
contents, contents,
subject, subject,
cc,
bcc,
purpose: "custom", purpose: "custom",
automation, automation,
}, },

View file

@ -10,6 +10,8 @@ exports.sendEmail = async ctx => {
contents, contents,
from, from,
subject, subject,
cc,
bcc,
automation, automation,
} = ctx.request.body } = ctx.request.body
let user let user
@ -23,6 +25,8 @@ exports.sendEmail = async ctx => {
contents, contents,
from, from,
subject, subject,
cc,
bcc,
automation, automation,
}) })
ctx.body = { ctx.body = {

View file

@ -13,6 +13,12 @@ function buildEmailSendValidation() {
email: Joi.string().email({ email: Joi.string().email({
multiple: true, multiple: true,
}), }),
cc: Joi.string().email({
multiple: true,
}).allow("", null),
bcc: Joi.string().email({
multiple: true,
}).allow("", null),
purpose: Joi.string().valid(...Object.values(EmailTemplatePurpose)), purpose: Joi.string().valid(...Object.values(EmailTemplatePurpose)),
workspaceId: Joi.string().allow("", null), workspaceId: Joi.string().allow("", null),
from: Joi.string().allow("", null), from: Joi.string().allow("", null),

View file

@ -174,7 +174,7 @@ exports.isEmailConfigured = async (workspaceId = null) => {
exports.sendEmail = async ( exports.sendEmail = async (
email, email,
purpose, purpose,
{ workspaceId, user, from, contents, subject, info, automation } = {} { workspaceId, user, from, contents, subject, info, cc, bcc, automation } = {}
) => { ) => {
const db = getGlobalDB() const db = getGlobalDB()
let config = (await getSmtpConfiguration(db, workspaceId, automation)) || {} let config = (await getSmtpConfiguration(db, workspaceId, automation)) || {}
@ -197,6 +197,8 @@ exports.sendEmail = async (
message = { message = {
...message, ...message,
to: email, to: email,
cc: cc,
bcc: bcc,
} }
if (subject || config.subject) { if (subject || config.subject) {