Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
63 changes: 61 additions & 2 deletions components/resend/actions/send-email/send-email.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { defineAction } from "@pipedream/types";
import app from "../../app/resend.app";
import {
getFileStreamAndMetadata, ConfigurationError,
} from "@pipedream/platform";

export default defineAction({
name: "Send Email",
description:
"Send an email [See the documentation](https://resend.com/docs/api-reference/emails/send-email)",
key: "resend-send-email",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
app,
Expand Down Expand Up @@ -56,12 +59,67 @@ export default defineAction({
description: "Reply-to email address(es).",
optional: true,
},
attachmentFiles: {
type: "string[]",
label: "File Paths or URLs",
description: "Provide either file URLs or paths to files in the /tmp directory (for example, /tmp/myFile.pdf)",
optional: true,
},
attachmentsBase64: {
type: "string[]",
label: "Base64-encoded attachments",
description: "Provide base64-encoded attachments",
optional: true,
},
base64AttachmentFilenames: {
type: "string[]",
label: "Base64-encoded attachment filenames",
description: "Provide the filenames for the base64-encoded attachments",
optional: true,
},
},
methods: {
async streamToBuffer(stream): Promise<Buffer> {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("end", () => resolve(Buffer.concat(chunks)));
stream.on("error", reject);
});
},
},
async run({ $ }) {
const {
from, to, subject, html, text, cc, bcc, replyTo,
from, to, subject, html, text, cc, bcc, replyTo, attachmentFiles, attachmentsBase64, base64AttachmentFilenames,
} = this;

const attachments = [];
if (attachmentFiles) {
for (const file of attachmentFiles) {
const {
stream, metadata,
} = await getFileStreamAndMetadata(file);
const buffer = await this.streamToBuffer(stream);
const base64 = buffer.toString("base64");
attachments.push({
name: metadata.name,
content: base64,
});
}
}

if (attachmentsBase64) {
if (attachmentsBase64.length !== base64AttachmentFilenames.length) {
throw new ConfigurationError("The number of base64-encoded attachments must match the number of base64-encoded attachment filenames");
}
for (let i = 1; i <= attachmentsBase64.length; i++) {
attachments.push({
name: base64AttachmentFilenames[i - 1],
content: attachmentsBase64[i - 1],
});
}
}

const params = {
$,
data: {
Expand All @@ -73,6 +131,7 @@ export default defineAction({
cc,
bcc,
reply_to: replyTo,
attachments,
},
};

Expand Down
2 changes: 1 addition & 1 deletion components/resend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/resend",
"version": "0.1.1",
"version": "0.1.2",
"description": "Pipedream Resend Components",
"main": "dist/app/resend.app.mjs",
"keywords": [
Expand Down
Loading
Loading