Skip to content

Commit 9ba89cb

Browse files
committed
some adjusts
1 parent 8a3598f commit 9ba89cb

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import fs from "fs";
3+
import mime from "mime";
24
import validate from "validate.js";
35
import common from "../common/common.mjs";
46

@@ -163,17 +165,22 @@ export default {
163165
return props;
164166
},
165167
async run({ $ }) {
168+
if (!this.personalizations && !this.toEmails) {
169+
throw new ConfigurationError("Please input either Personalization or Recipient Emails.");
170+
}
166171
const personalizations = this.personalizations || [];
167172
if (personalizations.length == 0) {
168-
for (const toEmail of this.toEmails) {
169-
const personalization = {
170-
to: [
171-
{
172-
email: toEmail,
173-
},
174-
],
175-
};
176-
personalizations.push(personalization);
173+
if (this.convertEmptyStringToUndefined(this.toEmails)) {
174+
for (const toEmail of this.toEmails) {
175+
const personalization = {
176+
to: [
177+
{
178+
email: toEmail,
179+
},
180+
],
181+
};
182+
personalizations.push(personalization);
183+
}
177184
}
178185
}
179186
if (this.dynamicTemplateData) {
@@ -205,9 +212,10 @@ export default {
205212
const content = fs.readFileSync(filepath, {
206213
encoding: "base64",
207214
});
215+
const type = mime.getType(filepath);
208216
attachments.push({
209217
content,
210-
type: "text/plain",
218+
type,
211219
filename: this[`attachmentsName${i}`],
212220
});
213221
}
@@ -217,7 +225,7 @@ export default {
217225
type: "array",
218226
};
219227
}
220-
this.sendAt = this.convertEmptyStringToUndefined(this.sendAt);
228+
this.sendAt = this.convertEmptyStringToUndefined(Date.parse(this.sendAt));
221229
if (this.sendAt != null) {
222230
constraints.sendAt = this.getIntegerGtZeroConstraint();
223231
}

components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "fs";
2+
import mime from "mime";
23
import validate from "validate.js";
34
import common from "../common/common.mjs";
45

@@ -7,7 +8,7 @@ export default {
78
key: "sendgrid-send-email-single-recipient",
89
name: "Send Email Single Recipient",
910
description: "This action sends a personalized e-mail to the specified recipient. [See the docs here](https://docs.sendgrid.com/api-reference/mail-send/mail-send)",
10-
version: "0.0.8",
11+
version: "0.0.1",
1112
type: "action",
1213
props: {
1314
...common.props,
@@ -230,9 +231,10 @@ export default {
230231
const content = fs.readFileSync(filepath, {
231232
encoding: "base64",
232233
});
234+
const type = mime.getType(filepath);
233235
attachments.push({
234236
content,
235-
type: "text/plain",
237+
type,
236238
filename: this[`attachmentsName${i}`],
237239
});
238240
}
@@ -247,7 +249,7 @@ export default {
247249
email: true,
248250
};
249251
}
250-
this.sendAt = this.convertEmptyStringToUndefined(this.sendAt);
252+
this.sendAt = this.convertEmptyStringToUndefined(Date.parse(this.sendAt));
251253
if (this.sendAt != null) {
252254
constraints.sendAt = this.getIntegerGtZeroConstraint();
253255
}

components/sendgrid/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"async-retry": "^1.3.1",
1717
"fs": "^0.0.1-security",
1818
"lodash": "^4.17.20",
19+
"mime": "^4.0.6",
1920
"uuid": "^8.3.2",
2021
"validate.js": "^0.13.1"
2122
},

components/sendgrid/sendgrid.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default {
241241
sendAt: {
242242
type: "integer",
243243
label: "Send At",
244-
description: "A unix timestamp allowing you to specify when you want your email to be delivered. This may be overridden by the `send_at` parameter set at the personalizations level. Delivery cannot be scheduled more than 72 hours in advance. If you have the flexibility, it's better to schedule mail for off-peak times. Most emails are scheduled and sent at the top of the hour or half hour. Scheduling email to avoid peak times — for example, scheduling at 10:53 — can result in lower deferral rates due to the reduced traffic during off-peak times.",
244+
description: "An ISO 8601 formatted date-time (YYYY-MM-DDTHH:MM:SSZ) allowing you to specify when you want your email to be delivered. This may be overridden by the `send_at` parameter set at the personalizations level. Delivery cannot be scheduled more than 72 hours in advance. If you have the flexibility, it's better to schedule mail for off-peak times. Most emails are scheduled and sent at the top of the hour or half hour. Scheduling email to avoid peak times — for example, scheduling at 10:53 — can result in lower deferral rates due to the reduced traffic during off-peak times.",
245245
optional: true,
246246
},
247247
asm: {

0 commit comments

Comments
 (0)