1
0
Fork 0
mirror of synced 2024-09-21 20:01:32 +12:00
budibase/packages/server/src/automations/steps/sendSmtpEmail.ts

93 lines
2.1 KiB
TypeScript
Raw Normal View History

import { sendSmtpEmail } from "../../utilities/workerRequests"
2022-11-27 04:10:41 +13:00
import * as automationUtils from "../automationUtils"
import {
AutomationActionStepId,
2022-11-27 04:10:41 +13:00
AutomationStepSchema,
AutomationStepInput,
AutomationStepType,
AutomationIOType,
} from "@budibase/types"
2022-11-27 04:10:41 +13:00
export const definition: AutomationStepSchema = {
description: "Send an email using SMTP",
tagline: "Send SMTP email to {{inputs.to}}",
icon: "Email",
name: "Send Email (SMTP)",
type: AutomationStepType.ACTION,
internal: true,
stepId: AutomationActionStepId.SEND_EMAIL_SMTP,
inputs: {},
schema: {
inputs: {
properties: {
to: {
type: AutomationIOType.STRING,
title: "Send To",
},
from: {
type: AutomationIOType.STRING,
title: "Send From",
},
2022-09-22 02:58:04 +12:00
cc: {
type: AutomationIOType.STRING,
2022-09-22 02:58:04 +12:00
title: "CC",
},
bcc: {
type: AutomationIOType.STRING,
2022-09-22 02:58:04 +12:00
title: "BCC",
},
subject: {
type: AutomationIOType.STRING,
title: "Email Subject",
},
contents: {
type: AutomationIOType.STRING,
title: "HTML Contents",
},
},
required: ["to", "from", "subject", "contents"],
},
outputs: {
properties: {
success: {
type: AutomationIOType.BOOLEAN,
description: "Whether the email was sent",
},
response: {
type: AutomationIOType.OBJECT,
description: "A response from the email client, this may be an error",
},
},
required: ["success"],
},
},
}
export async function run({ inputs }: AutomationStepInput) {
2022-09-22 02:58:04 +12:00
let { to, from, subject, contents, cc, bcc } = inputs
if (!contents) {
contents = "<h1>No content</h1>"
}
to = to || undefined
try {
2022-09-22 02:58:04 +12:00
let response = await sendSmtpEmail(
to,
from,
subject,
contents,
cc,
bcc,
true
)
return {
success: true,
response,
}
} catch (err) {
return {
success: false,
response: automationUtils.getError(err),
}
}
}