Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
130 changes: 130 additions & 0 deletions components/smtp2go/actions/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import smtp2go from "../smtp2go.app";

export default {
props: {
smtp2go,
fromEmail: {
type: "string",
label: "\"From\" email address",
description:
"The sender email address. To include a name, use the format 'Full Name <sender@domain.com>' for the address.",
},
toEmail: {
type: "string",
label: "Recipient email address(es)",
description:
"Recipient email address. Multiple addresses are comma separated. Max 50.",
},
ccEmail: {
type: "string",
label: "CC email address(es)",
description:
"Cc recipient email address. Multiple addresses are comma separated. Max 50.",
optional: true,
},
bccEmail: {
type: "string",
label: "BCC email address(es)",
description:
"Bcc recipient email address. Multiple addresses are comma separated. Max 50.",
optional: true,
},
replyTo: {
type: "string",
label: "\"Reply To\" email address",
description:
"Reply To override email address. Defaults to the Reply To set in the sender signature.",
optional: true,
},
customHeaders: {
type: "string[]",
label: "Custom Headers",
description: `List of custom headers to include.
\\
Each attachment should be a string with the parameters separated by a pipe character \`|\`, in the format: \`header|value\`. Alternatively, you can pass a string representing an object. Both parameters are required:
\\
\\
\`header\` - the header key name, i.e. \`some-header\`
\\
\`value\` - the string value of the header, i.e. \`the-value\`
\\
\\
Example with pipe-separated parameters: \`some-custom-header|the-value\`
\\
Example with JSON-stringified object: \`{"header":"some-custom-header","value":"the-value"}\`
`,
optional: true,
},
attachments: {
type: "string[]",
label: "Attachments",
description: `List of attachments to include.
\\
Each attachment should be a string with the parameters separated by a pipe character \`|\`, in the format: \`Name|Content|ContentType\`. Alternatively, you can pass a string representing an object. All three parameters are required:
\\
\\
\`filename\` - the filename with extension, i.e. \`readme.txt\`
\\
\`fileblob\` - the base64-encoded string with the binary data for the file, i.e. \`dGVzdCBjb250ZW50\`
\\
\`mimetype\` - the MIME content type, i.e. \`text/plain\`
\\
\\
Example with pipe-separated parameters: \`readme.txt|dGVzdCBjb250ZW50|text/plain\`
\\
Example with JSON-stringified object: \`{"filename":"readme.txt","fileblob":"dGVzdCBjb250ZW50","mimetype":"text/plain"}\`
`,
optional: true,
},
ignoreFailures: {
type: "boolean",
label: "Ignore Failures",
description: "Should this action ignore failures to send an email?",
optional: true
}
},
methods: {
getActionRequestCommonData() {
return {
from: this.fromEmail,
to: this.toEmail,
cc: this.ccEmail,
bcc: this.bccEmail,
reply_to: this.replyTo,
custom_headers: [...this.getHeaderData(this.customHeaders), ...this.getReplyToHeaders(this.replyTo)],
attachments: this.getAttachmentData(this.attachments)
};
},
getAttachmentData(attachments: any[]) {
return attachments?.map((str) => {
let params = str.split("|");
return params.length === 3
? {
filename: params[0],
fileblob: params[1],
mimetype: params[2],
}
: JSON.parse(str);
});
},
getReplyToHeaders(replyToEmail: string) {
return reply_to ? [
{
header: "Reply-To",
value: reply_to
}
] : [];
},
getCustomHeaderData(headers: any[]) {
return headers?.map((str) => {
let params = str.split("|");
return params.length === 2
? {
header: params[0],
value: params[1]
}
: JSON.parse(str);
});
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import common from "../common.mjs";

export default {
...common,
key: "smtp2go-send-single-email",
name: "Send Single Email with Template",
description: "Send a single email with SMTP2GO using a pre-defined template and data object [(See docs here)](https://apidoc.smtp2go.com/documentation/#/POST%20/email/send)",
version: "0.1.0",
type: "action",
props: {
subject: {
type: "string",
label: "Subject",
description: "Email subject.",
},
templateId: {
type: "string",
label: "Template ID",
description: "The ID of the pre-defined template in SMTP2GO.",
},
templateModel: {
type: "object",
label: "Template Model",
description:
"The model to be applied to the specified template to generate the email body and subject.",
},
// The above props are intentionally placed first
...common.props,
},
async run({ $ }) {
const data = {
...this.getActionRequestCommonData(),
template_id: this.templateId,
template_data: this.templateModel
};
const response = await this.smtp2go.sendSingleEmailWithTemplate($, data, this.ignoreFailures);
$.export("$summary", `Sent email successfully with email ID ${response.data.email_id}`);
return response;
},
};
51 changes: 51 additions & 0 deletions components/smtp2go/actions/send-single-email/send-single-email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import common from "../common.mjs";

export default {
...common,
key: "smtp2go-send-single-email",
name: "Send Single Email",
description: "Send a single email with SMTP2GO [(See docs here)](https://apidoc.smtp2go.com/documentation/#/POST%20/email/send)",
version: "0.1.0",
type: "action",
props: {
subject: {
type: "string",
label: "Subject",
description: "Email subject.",
},
htmlBody: {
type: "string",
label: "HTML Body",
description:
`HTML email message.
\\
**Required** if no \`Text Body\` is specified.`,
optional: true,
},
textBody: {
type: "string",
label: "Text Body",
description:
`Plain text email message.
\\
**Required** if no \`HTML Body\` is specified.`,
optional: true,
},
// The above props are intentionally placed first
...common.props,
},
async run({ $ }) {
const data = {
...this.getActionRequestCommonData(),
subject: this.subject,
html_body: this.htmlBody,
text_body: this.textBody
};
if(!data.html_body && !data.text_body){
throw new Error("You must have EITHER a text body or an html body. Neither were provided.");
}
const response = await this.smtp2go.sendSingleEmail($, data, this.ignoreFailures);
$.export("$summary", `Sent email successfully with email ID ${response.data.email_id}`);
return response;
},
};
13 changes: 0 additions & 13 deletions components/smtp2go/app/smtp2go.app.ts

This file was deleted.

6 changes: 3 additions & 3 deletions components/smtp2go/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@pipedream/smtp2go",
"version": "0.0.1",
"description": "Pipedream SMTP2GO Components",
"main": "dist/app/smtp2go.app.mjs",
"description": "Pipedream SMTP2GO Components",
"main": "dist/smtp2go.app.ts",
"keywords": [
"pipedream",
"smtp2go"
Expand All @@ -14,4 +14,4 @@
"publishConfig": {
"access": "public"
}
}
}
52 changes: 52 additions & 0 deletions components/smtp2go/smtp2go.app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "smtp2go",
methods: {
_apikey() {
return this.$auth.api_key;
},
getHeaders() {
return {
"Content-Type": "application/json",
};
},
async sharedRequest($, params) {
const {
endpoint,
method,
data,
} = params;

return axios($, {
url: `https://api.smtp2go.com/v3/${endpoint}`,
method,
headers: this.getHeaders(),
data: { ...data, api_key: this._apikey },
});
},
async sharedActionRequest($, endpoint: string, data: any) {
return this.sharedRequest($, {
endpoint,
method: "POST",
data,
});
},
verifiedSent(result){
if(result.data.failed>0){
throw new Error(`Mail sender responded with the following error(s): ${string.join(result.data.failures, ",")}`);
}
},
async sendSingleEmail($, data: { sender: string, to: string[], cc: string[], bcc: string[], subject: string, text_body: string, html_body: string, attachments: any[], custom_headers: any[] }, ignoreFailures: boolean) {
const result = this.sharedActionRequest($, "email/send", data);
if(ignoreFailures) return result;
return this.verifiedSent(result);
},
async sendSingleEmailWithTemplate($, data: { sender: string, to: string[], cc: string[], bcc: string[], subject: string, template_id: string, template_data: any, attachments: any[], custom_headers: any[] }, ignoreFailures: boolean) {
const result = this.sharedActionRequest($, "email/send", data);
if(ignoreFailures) return result;
return this.verifiedSent(result);
}
},
};