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