Skip to content

Commit a842fdf

Browse files
authored
Merging pull request #18284
* add attachment support * pnpm-lock.yaml * updates * updates
1 parent b541381 commit a842fdf

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

components/resend/actions/send-email/send-email.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { defineAction } from "@pipedream/types";
22
import app from "../../app/resend.app";
3+
import {
4+
getFileStreamAndMetadata, ConfigurationError,
5+
} from "@pipedream/platform";
36

47
export default defineAction({
58
name: "Send Email",
69
description:
710
"Send an email [See the documentation](https://resend.com/docs/api-reference/emails/send-email)",
811
key: "resend-send-email",
9-
version: "0.0.1",
12+
version: "0.0.2",
1013
type: "action",
1114
props: {
1215
app,
@@ -40,7 +43,7 @@ export default defineAction({
4043
},
4144
cc: {
4245
type: "string",
43-
label: "CCc",
46+
label: "Cc",
4447
description: "Cc recipient email address(es).",
4548
optional: true,
4649
},
@@ -56,12 +59,67 @@ export default defineAction({
5659
description: "Reply-to email address(es).",
5760
optional: true,
5861
},
62+
attachmentFiles: {
63+
type: "string[]",
64+
label: "File Paths or URLs",
65+
description: "Provide either file URLs or paths to files in the /tmp directory (for example, /tmp/myFile.pdf)",
66+
optional: true,
67+
},
68+
attachmentsBase64: {
69+
type: "string[]",
70+
label: "Base64-encoded attachments",
71+
description: "Provide base64-encoded attachments",
72+
optional: true,
73+
},
74+
base64AttachmentFilenames: {
75+
type: "string[]",
76+
label: "Base64-encoded attachment filenames",
77+
description: "Provide the filenames for the base64-encoded attachments",
78+
optional: true,
79+
},
80+
},
81+
methods: {
82+
async streamToBuffer(stream): Promise<Buffer> {
83+
return new Promise((resolve, reject) => {
84+
const chunks: Buffer[] = [];
85+
stream.on("data", (chunk) => chunks.push(chunk));
86+
stream.on("end", () => resolve(Buffer.concat(chunks)));
87+
stream.on("error", reject);
88+
});
89+
},
5990
},
6091
async run({ $ }) {
6192
const {
62-
from, to, subject, html, text, cc, bcc, replyTo,
93+
from, to, subject, html, text, cc, bcc, replyTo, attachmentFiles, attachmentsBase64, base64AttachmentFilenames,
6394
} = this;
6495

96+
const attachments = [];
97+
if (attachmentFiles) {
98+
for (const file of attachmentFiles) {
99+
const {
100+
stream, metadata,
101+
} = await getFileStreamAndMetadata(file);
102+
const buffer = await this.streamToBuffer(stream);
103+
const base64 = buffer.toString("base64");
104+
attachments.push({
105+
filename: metadata.name,
106+
content: base64,
107+
});
108+
}
109+
}
110+
111+
if (attachmentsBase64) {
112+
if (attachmentsBase64.length !== base64AttachmentFilenames.length) {
113+
throw new ConfigurationError("The number of base64-encoded attachments must match the number of base64-encoded attachment filenames");
114+
}
115+
for (let i = 0; i < attachmentsBase64.length; i++) {
116+
attachments.push({
117+
filename: base64AttachmentFilenames[i],
118+
content: attachmentsBase64[i],
119+
});
120+
}
121+
}
122+
65123
const params = {
66124
$,
67125
data: {
@@ -73,6 +131,7 @@ export default defineAction({
73131
cc,
74132
bcc,
75133
reply_to: replyTo,
134+
attachments,
76135
},
77136
};
78137

components/resend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/resend",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Pipedream Resend Components",
55
"main": "dist/app/resend.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)