-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - mailosaur #16666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - mailosaur #16666
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea73453
mailosaur init
luancazarine 6a3b772
[Components] mailosaur #16655
luancazarine 7ddb44c
pnpm update
luancazarine 7058b72
Merge branch 'master' into issue-16655
luancazarine e5df4c0
pnpm update
luancazarine 9cd2cb1
some adjusts
luancazarine f5f3ca1
some adjusts
luancazarine 23645e3
Merge branch 'master' into issue-16655
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
components/mailosaur/actions/create-email/create-email.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
37
components/mailosaur/actions/delete-email/delete-email.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
98
components/mailosaur/actions/search-email/search-email.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.