Skip to content

Commit 7ac38a8

Browse files
authored
New Components - mailosaur (#16666)
* mailosaur init * [Components] mailosaur #16655 Sources - New Message - New Message Macthing Criteira Actions - Create Email - Search Message - Delete Message * pnpm update * pnpm update * some adjusts * some adjusts
1 parent 5b8ea6f commit 7ac38a8

File tree

12 files changed

+557
-8
lines changed

12 files changed

+557
-8
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import mailosaur from "../../mailosaur.app.mjs";
3+
4+
export default {
5+
key: "mailosaur-create-email",
6+
name: "Create and Send Email via Mailosaur",
7+
description: "Sends an email through Mailosaur. [See the documentation](https://mailosaur.com/docs/api)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
mailosaur,
12+
serverId: {
13+
propDefinition: [
14+
mailosaur,
15+
"serverId",
16+
],
17+
},
18+
to: {
19+
type: "string",
20+
label: "To",
21+
description: "The verified external email address to which the email should be sent.",
22+
},
23+
from: {
24+
type: "string",
25+
label: "From",
26+
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`.",
27+
optional: true,
28+
},
29+
subject: {
30+
type: "string",
31+
label: "Subject",
32+
description: "The subject line for an email.",
33+
},
34+
html: {
35+
type: "object",
36+
label: "HTML",
37+
description: "An object with HTML properties. Please [see the documentation](https://mailosaur.com/docs/api#send-an-email) for more details.",
38+
optional: true,
39+
},
40+
text: {
41+
type: "object",
42+
label: "Text",
43+
description: "An object with Plain text properties. Please [see the documentation](https://mailosaur.com/docs/api#send-an-email) for more details.",
44+
optional: true,
45+
},
46+
send: {
47+
type: "boolean",
48+
label: "Send",
49+
description: "If `false`, the email will be created in your server, but will not be sent.",
50+
},
51+
},
52+
async run({ $ }) {
53+
if ((!!this.send) && (!this.html && !this.text)) {
54+
throw new ConfigurationError("Please provide either HTML or plain text content.");
55+
}
56+
57+
const {
58+
mailosaur,
59+
serverId,
60+
...data
61+
} = this;
62+
63+
const response = await mailosaur.sendEmail({
64+
$,
65+
params: {
66+
server: serverId,
67+
},
68+
data,
69+
});
70+
71+
$.export("$summary", `Email sent successfully to ${this.to}`);
72+
return response;
73+
},
74+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import mailosaur from "../../mailosaur.app.mjs";
2+
3+
export default {
4+
key: "mailosaur-delete-email",
5+
name: "Delete Email",
6+
description: "Deletes an email from a Mailosaur server using its email ID. [See the documentation](https://mailosaur.com/docs/api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
mailosaur,
11+
serverId: {
12+
propDefinition: [
13+
mailosaur,
14+
"serverId",
15+
],
16+
},
17+
emailId: {
18+
propDefinition: [
19+
mailosaur,
20+
"emailId",
21+
({ serverId }) => ({
22+
serverId,
23+
}),
24+
],
25+
},
26+
},
27+
async run({ $ }) {
28+
await this.mailosaur.deleteEmail({
29+
$,
30+
emailId: this.emailId,
31+
});
32+
$.export("$summary", `Successfully deleted email with ID ${this.emailId}`);
33+
return {
34+
emailId: this.emailId,
35+
};
36+
},
37+
};
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { MATCH_OPTIONS } from "../../common/constants.mjs";
2+
import mailosaur from "../../mailosaur.app.mjs";
3+
4+
export default {
5+
key: "mailosaur-search-email",
6+
name: "Search Email",
7+
description: "Search for received emails in a server matching specified criteria. [See the documentation](https://mailosaur.com/docs/api/#search-for-messages)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
mailosaur,
12+
serverId: {
13+
propDefinition: [
14+
mailosaur,
15+
"serverId",
16+
],
17+
},
18+
receiveAfter: {
19+
type: "string",
20+
label: "Receive After",
21+
description:
22+
"Limits results to only messages received after this date/time.",
23+
optional: true,
24+
},
25+
page: {
26+
type: "integer",
27+
label: "Page",
28+
description: "Used in conjunction with `itemsPerPage` to support pagination.",
29+
optional: true,
30+
},
31+
itemsPerPage: {
32+
type: "integer",
33+
label: "Items Per Page",
34+
description:
35+
"A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, default is 50.",
36+
optional: true,
37+
},
38+
dir: {
39+
type: "string",
40+
label: "Direction",
41+
description: "Optionally limits results based on the direction (`Sent` or `Received`).",
42+
optional: true,
43+
},
44+
sentFrom: {
45+
type: "string",
46+
label: "Sent From",
47+
description: "The full email address from which the target message was sent.",
48+
optional: true,
49+
},
50+
sentTo: {
51+
type: "string",
52+
label: "Sent To",
53+
description: "The full email address to which the target message was sent.",
54+
optional: true,
55+
},
56+
subject: {
57+
type: "string",
58+
label: "Subject",
59+
description: "The value to seek within the target email's subject line.",
60+
optional: true,
61+
},
62+
body: {
63+
type: "string",
64+
label: "Body",
65+
description: "The value to seek within the target message's HTML or text body.",
66+
optional: true,
67+
},
68+
match: {
69+
type: "string",
70+
label: "Match",
71+
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.",
72+
options: MATCH_OPTIONS,
73+
optional: true,
74+
},
75+
},
76+
async run({ $ }) {
77+
const response = await this.mailosaur.searchMessages({
78+
$,
79+
params: {
80+
server: this.serverId,
81+
receiveAfter: this.receiveAfter,
82+
page: this.page,
83+
itemsPerPage: this.itemsPerPage,
84+
dir: this.dir,
85+
},
86+
data: {
87+
sentFrom: this.sentFrom,
88+
sentTo: this.sentTo,
89+
subject: this.subject,
90+
body: this.body,
91+
match: this.match,
92+
},
93+
});
94+
95+
$.export("$summary", `Successfully retrieved ${response.items.length} email(s) from server.`);
96+
return response;
97+
},
98+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const LIMIT = 1000;
2+
3+
export const MATCH_OPTIONS = [
4+
{
5+
label: "All",
6+
value: "ALL",
7+
},
8+
{
9+
label: "Any",
10+
value: "ANY",
11+
},
12+
];
Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,123 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "mailosaur",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
serverId: {
9+
type: "string",
10+
label: "Server ID",
11+
description: "The identifier of the server from which the email should be sent.",
12+
async options() {
13+
const { items } = await this.listServers();
14+
15+
return items.map(({
16+
id: value, name: label,
17+
}) => ({
18+
label,
19+
value,
20+
}));
21+
},
22+
},
23+
emailId: {
24+
type: "string",
25+
label: "Server ID",
26+
description: "The identifier of the server from which the email should be sent.",
27+
async options({ serverId }) {
28+
const { items } = await this.listMessages({
29+
params: {
30+
server: serverId,
31+
},
32+
});
33+
34+
return items.map(({
35+
id: value, subject: label,
36+
}) => ({
37+
label,
38+
value,
39+
}));
40+
},
41+
},
42+
},
543
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
44+
_baseUrl() {
45+
return "https://mailosaur.com/api";
46+
},
47+
_auth() {
48+
return {
49+
username: "api",
50+
password: `${this.$auth.api_key}`,
51+
};
52+
},
53+
_makeRequest({
54+
$ = this, path, ...opts
55+
}) {
56+
return axios($, {
57+
url: this._baseUrl() + path,
58+
auth: this._auth(),
59+
...opts,
60+
});
61+
},
62+
listServers() {
63+
return this._makeRequest({
64+
path: "/servers",
65+
});
66+
},
67+
listMessages(opts = {}) {
68+
return this._makeRequest({
69+
path: "/messages",
70+
...opts,
71+
});
72+
},
73+
sendEmail(opts = {}) {
74+
return this._makeRequest({
75+
method: "POST",
76+
path: "/messages",
77+
...opts,
78+
});
79+
},
80+
searchMessages(opts = {}) {
81+
return this._makeRequest({
82+
method: "POST",
83+
path: "/messages/search",
84+
...opts,
85+
});
86+
},
87+
deleteEmail({
88+
emailId, ...opts
89+
}) {
90+
return this._makeRequest({
91+
method: "DELETE",
92+
path: `/messages/${emailId}`,
93+
...opts,
94+
});
95+
},
96+
async *paginate({
97+
fn, params = {}, maxResults = null, ...opts
98+
}) {
99+
let hasMore = false;
100+
let count = 0;
101+
let page = 0;
102+
103+
do {
104+
params.page = page++;
105+
params.itemsPerPage = LIMIT;
106+
const { items } = await fn({
107+
params,
108+
...opts,
109+
});
110+
for (const d of items) {
111+
yield d;
112+
113+
if (maxResults && ++count === maxResults) {
114+
return count;
115+
}
116+
}
117+
118+
hasMore = items.length;
119+
120+
} while (hasMore);
9121
},
10122
},
11-
};
123+
};

components/mailosaur/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/mailosaur",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Mailosaur Components",
55
"main": "mailosaur.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)