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
74 changes: 74 additions & 0 deletions components/mailosaur/actions/create-email/create-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { ConfigurationError } from "@pipedream/platform";
import mailosaur from "../../mailosaur.app.mjs";

export default {
key: "mailosaur-create-email",
name: "Create and Send Email via Mailosaur",
description: "Sends an email through Mailosaur. [See the documentation](https://mailosaur.com/docs/api)",
version: "0.0.1",
type: "action",
props: {
mailosaur,
serverId: {
propDefinition: [
mailosaur,
"serverId",
],
},
to: {
type: "string",
label: "To",
description: "The verified external email address to which the email should be sent.",
},
from: {
type: "string",
label: "From",
description: "Optionally overrides of the message's `from` address. This **must** be an address ending with `YOUR_SERVER.mailosaur.net`, such as `my-emails @a1bcdef2.mailosaur.net`.",
optional: true,
},
subject: {
type: "string",
label: "Subject",
description: "The subject line for an email.",
},
html: {
type: "object",
label: "HTML",
description: "An object with HTML properties. Please [see the documentation](https://mailosaur.com/docs/api#send-an-email) for more details.",
optional: true,
},
text: {
type: "object",
label: "Text",
description: "An object with Plain text properties. Please [see the documentation](https://mailosaur.com/docs/api#send-an-email) for more details.",
optional: true,
},
send: {
type: "boolean",
label: "Send",
description: "If `false`, the email will be created in your server, but will not be sent.",
},
},
async run({ $ }) {
if ((!!this.send) && (!this.html && !this.text)) {
throw new ConfigurationError("Please provide either HTML or plain text content.");
}

const {
mailosaur,
serverId,
...data
} = this;

const response = await mailosaur.sendEmail({
$,
params: {
server: serverId,
},
data,
});

$.export("$summary", `Email sent successfully to ${this.to}`);
return response;
},
};
37 changes: 37 additions & 0 deletions components/mailosaur/actions/delete-email/delete-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import mailosaur from "../../mailosaur.app.mjs";

export default {
key: "mailosaur-delete-email",
name: "Delete Email",
description: "Deletes an email from a Mailosaur server using its email ID. [See the documentation](https://mailosaur.com/docs/api)",
version: "0.0.1",
type: "action",
props: {
mailosaur,
serverId: {
propDefinition: [
mailosaur,
"serverId",
],
},
emailId: {
propDefinition: [
mailosaur,
"emailId",
({ serverId }) => ({
serverId,
}),
],
},
},
async run({ $ }) {
await this.mailosaur.deleteEmail({
$,
emailId: this.emailId,
});
$.export("$summary", `Successfully deleted email with ID ${this.emailId}`);
return {
emailId: this.emailId,
};
},
};
98 changes: 98 additions & 0 deletions components/mailosaur/actions/search-email/search-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { MATCH_OPTIONS } from "../../common/constants.mjs";
import mailosaur from "../../mailosaur.app.mjs";

export default {
key: "mailosaur-search-email",
name: "Search Email",
description: "Search for received emails in a server matching specified criteria. [See the documentation](https://mailosaur.com/docs/api/#search-for-messages)",
version: "0.0.1",
type: "action",
props: {
mailosaur,
serverId: {
propDefinition: [
mailosaur,
"serverId",
],
},
receiveAfter: {
type: "string",
label: "Receive After",
description:
"Limits results to only messages received after this date/time.",
optional: true,
},
page: {
type: "integer",
label: "Page",
description: "Used in conjunction with `itemsPerPage` to support pagination.",
optional: true,
},
itemsPerPage: {
type: "integer",
label: "Items Per Page",
description:
"A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, default is 50.",
optional: true,
},
dir: {
type: "string",
label: "Direction",
description: "Optionally limits results based on the direction (`Sent` or `Received`).",
optional: true,
},
sentFrom: {
type: "string",
label: "Sent From",
description: "The full email address from which the target message was sent.",
optional: true,
},
sentTo: {
type: "string",
label: "Sent To",
description: "The full email address to which the target message was sent.",
optional: true,
},
subject: {
type: "string",
label: "Subject",
description: "The value to seek within the target email's subject line.",
optional: true,
},
body: {
type: "string",
label: "Body",
description: "The value to seek within the target message's HTML or text body.",
optional: true,
},
match: {
type: "string",
label: "Match",
description: "If set to `ALL` (default), only results matching all criteria will be returned. If set to `ANY`, results matching any criteria will be returned.",
options: MATCH_OPTIONS,
optional: true,
},
},
async run({ $ }) {
const response = await this.mailosaur.searchMessages({
$,
params: {
server: this.serverId,
receiveAfter: this.receiveAfter,
page: this.page,
itemsPerPage: this.itemsPerPage,
dir: this.dir,
},
data: {
sentFrom: this.sentFrom,
sentTo: this.sentTo,
subject: this.subject,
body: this.body,
match: this.match,
},
});

$.export("$summary", `Successfully retrieved ${response.items.length} email(s) from server.`);
return response;
},
};
12 changes: 12 additions & 0 deletions components/mailosaur/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const LIMIT = 1000;

export const MATCH_OPTIONS = [
{
label: "All",
value: "ALL",
},
{
label: "Any",
value: "ANY",
},
];
122 changes: 117 additions & 5 deletions components/mailosaur/mailosaur.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "mailosaur",
propDefinitions: {},
propDefinitions: {
serverId: {
type: "string",
label: "Server ID",
description: "The identifier of the server from which the email should be sent.",
async options() {
const { items } = await this.listServers();

return items.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
emailId: {
type: "string",
label: "Server ID",
description: "The identifier of the server from which the email should be sent.",
async options({ serverId }) {
const { items } = await this.listMessages({
params: {
server: serverId,
},
});

return items.map(({
id: value, subject: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://mailosaur.com/api";
},
_auth() {
return {
username: "api",
password: `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
auth: this._auth(),
...opts,
});
},
listServers() {
return this._makeRequest({
path: "/servers",
});
},
listMessages(opts = {}) {
return this._makeRequest({
path: "/messages",
...opts,
});
},
sendEmail(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/messages",
...opts,
});
},
searchMessages(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/messages/search",
...opts,
});
},
deleteEmail({
emailId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/messages/${emailId}`,
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = page++;
params.itemsPerPage = LIMIT;
const { items } = await fn({
params,
...opts,
});
for (const d of items) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = items.length;

} while (hasMore);
},
},
};
};
7 changes: 5 additions & 2 deletions components/mailosaur/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/mailosaur",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Mailosaur Components",
"main": "mailosaur.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
Loading
Loading