Skip to content

Commit

Permalink
Initial commit for OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Hartzell committed Jun 29, 2023
1 parent f974cf2 commit f1df01e
Show file tree
Hide file tree
Showing 23 changed files with 9,864 additions and 27 deletions.
37 changes: 37 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
extends: [
'plugin:prettier/recommended',
'plugin:security/recommended',
],
plugins: [
'html'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'prefer-const': 'error',
'react/prop-types': 'off',
'react/display-name': 'off',
'security/detect-object-injection': 'off',
'no-unused-vars': 2,
'no-undef': 2,
'prettier/prettier': 'off',
'semi': 2
},
globals: {
Cypress: true,
RED: true,
$: true
},
env: {
'amd': true,
'node': true,
'es6': true,
'jest': true,
}
};
33 changes: 33 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
19 changes: 19 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: node
package-name: "@sinch/node-red-mailgun"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.DS_Store
.vscode

15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Contributing to @sinch/node-red-mailgun
All contributions are welcome. Here are some guidelines you must follow.

### Raising an issue
Raise the issue on the project's issue tracker and make sure that the issue hasn't been raised before.
Try to be as clear as possible in the description of your issue.
Include what Node-RED version and node.js version you're running.
Also, if possible, include a small example flow that can be used to reproduce the issue.

### Feature request
For now, features are requested by raising an issue on the project.

### Pull request
For pull-requests, make sure that the commit message follows the [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) specification.
If the pull-request relates to an issue, also include the issue number (#issuenumber) in the commit message.
29 changes: 2 additions & 27 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down Expand Up @@ -173,29 +173,4 @@
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
END OF TERMS AND CONDITIONS
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# @sinch/node-red-mailgun

A package of nodes for [Node-RED](https://nodered.org) which allows you to connect, send and receive emails through the Mailgun API. For more information about the Mailgun API and how to get started, see the [documentation](https://documentation.mailgun.com/en/latest/api_reference.html).

![Mailgun API](docs/images/mailgun-nodes.png)

## Installation

The first step is to install [Node-RED](https://nodered.org/docs/getting-started/local).

```
$ sudo npm install -g node-red
```

> Compatible with Node-Red version 3.x.x and later
The second step is to install the package. You can either install it directly using the Palette Manager. Instructions can be found here: [Node-RED](https://nodered.org/docs/user-guide/runtime/adding-nodes).

Or install manually using npm:

Navigate to the Node-RED installation and install the package:

```
$ cd ~/.node-red
$ npm install @sinch/node-red-mailgun
```

Run Node-RED locally:
```
$ node-red
```

This will start a server for Node-RED on [http://127.0.0.1:1880/](http://127.0.0.1:1880/).

If the installation of the node package was successful, the Mailgun nodes should be available in the node palette to the left, under the category "Mailgun".

## Get started
After you've installed Node-RED and the @sinch/node-red-mailgun package you can start building your flow. To get you started we provide an example [flows.json](docs/examples/flow.json) containing the essentials for sending and receiving emails. To import the flows.json file, open Node-RED in the brower and select the hamburger menu in the top right corner. Choose "Import" and press "select a file to import". The flow file will then be imported on a tab called "Example flow".

The flow.json contains two separate flow examples. For each of the flows there exists a comment node containing additional information about the configuration required to test it out.

### Testing
If you're running Node-RED locally on localhost and want to test receiving emails and events, we recommend using a tool like [Ngrok](https://ngrok.com/). This tool allow you to expose your localhost to the internet and makes it possible to route callback events to Node-RED. This is also a useful for testing the native Http-in node provided by Node-RED.

## More about the nodes
This package contains the following two nodes:

### Receive email node
Handles and routes incoming emails where the target email address field matches the configiured <strong>Match sender</strong> field.
Possible match creteria for the match sender field:
1. Exact match
2. Regular expression
3. Left empty (matches all)

In order to receive messages from Mailgun, you need to configure a route on the Mailgun [dashboard](https://app.mailgun.com/app/receiving/routes). The path should be: <i>&lt;node-red-path&gt;/mailgun/events-email</i>.


### Send email node
Sends emails through the Mailgun API. Can be configured to either send a plain text message or a template configured in the Mailgun [dashboard](https://app.mailgun.com/mg/dashboard). Sending -> Templates.

In order to receive events such as Delivered or Unsubscribed you need to configure a webhook for each event. This is also done in the Mailgun [dashboard](https://app.mailgun.com/mg/dashboard). Sending -> Webhooks. The path should be: <i>&lt;node-red-path&gt;/mailgun/events-email</i>.

## Contributing
See, [CONTRIBUTING.md](CONTRIBUTING.md).

## Copyright and license
Copyright Sinch AB, https://sinch.com under the [Apache 2.0 license](LICENSE).
157 changes: 157 additions & 0 deletions docs/examples/flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
[
{
"id": "d4d33e3a625cd210",
"type": "tab",
"label": "Example flow",
"disabled": false,
"info": "",
"env": []
},
{
"id": "db57b702790af355",
"type": "sinch-received-email",
"z": "d4d33e3a625cd210",
"name": "",
"recipient": "",
"x": 460,
"y": 540,
"wires": [
[
"dfcaf0edfb385044"
]
]
},
{
"id": "0e97984de773d8ce",
"type": "sinch-send-email",
"z": "d4d33e3a625cd210",
"name": "",
"baseUrl": "",
"apiKey": "",
"sender": "",
"recipient": "",
"subject": "",
"body": "",
"template": "",
"variables": [],
"tags": [],
"delivered": true,
"failed": false,
"unsubscribed": false,
"opened": false,
"clicked": false,
"complained": false,
"outputMap": "{\"default\":0,\"delivered\":1}",
"outputs": 2,
"x": 630,
"y": 320,
"wires": [
[
"fd78ce2a0d2d9d9a"
],
[
"880f36b661985a58"
]
]
},
{
"id": "3756cda309699ba3",
"type": "inject",
"z": "d4d33e3a625cd210",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 440,
"y": 320,
"wires": [
[
"0e97984de773d8ce"
]
]
},
{
"id": "fd78ce2a0d2d9d9a",
"type": "debug",
"z": "d4d33e3a625cd210",
"name": "log after sending",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 280,
"wires": []
},
{
"id": "880f36b661985a58",
"type": "debug",
"z": "d4d33e3a625cd210",
"name": "log delivery events",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 360,
"wires": []
},
{
"id": "dfcaf0edfb385044",
"type": "debug",
"z": "d4d33e3a625cd210",
"name": "log incoming email",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 540,
"wires": []
},
{
"id": "fc003d52e10ed1e3",
"type": "comment",
"z": "d4d33e3a625cd210",
"name": "README - Send Email",
"info": "This simple flow allows you to test sending \nemails using the Mailgun API.\n\n## Configuration\n1. **Base-url:** The base url that you've configured in mailgun, e.g. example.com\n2. **API-key:** An api-key provided by mailgun. Found in Mailgun dashboard under your profile -> API keys\n3. **Sender:** The sender email that you want to send the email from\n4. **Recipient:** The recipient email that you want to send the email to (can also be passed on msg.recipient)\n5. **Subject:** The subject title of the email. \n6. **Body:** Body text of the email that is used if no template is selected\n7. **Template:** Templates created in your mailgun account will be available here if you've entered valid base-url and API-key.\n Will be used instead of body if selected.\n8. **Variables:** Will replace variables configured in the template. e.g. {{firstname}}\n9. **Events:** Configure the events that you are interested in listening for. Each checked event will create a separate output on the node.\n",
"x": 480,
"y": 240,
"wires": []
},
{
"id": "2e2b04dbb4c9a415",
"type": "comment",
"z": "d4d33e3a625cd210",
"name": "README - Receive Email",
"info": "This simple flow allows you to test receiving \nemails from Mailgun. Listen for emails arriving to &lt;node-red-path&gt;/mailgun/events-email\n\n## Configuration\n**Match sender:** \nPossible match creteria for the Match sender field:\n1. Exact match: e.g. [email protected]\n2. Regular expression: e.g. ^[A-Za-z0-9._%+-]+@example\\.com$ will match all emails with the domain example.com.\n3. Left empty: matches all",
"x": 490,
"y": 460,
"wires": []
}
]
Binary file added docs/images/mailgun-nodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f1df01e

Please sign in to comment.