feat: Implement SMTP app connection
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
"http-errors": "~1.6.3",
|
"http-errors": "~1.6.3",
|
||||||
"knex": "^0.95.11",
|
"knex": "^0.95.11",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
|
"nodemailer": "6.7.0",
|
||||||
"objection": "^2.2.17",
|
"objection": "^2.2.17",
|
||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
"twitch-js": "2.0.0-beta.42",
|
"twitch-js": "2.0.0-beta.42",
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
"@types/http-errors": "^1.8.1",
|
"@types/http-errors": "^1.8.1",
|
||||||
"@types/morgan": "^1.9.3",
|
"@types/morgan": "^1.9.3",
|
||||||
"@types/node": "^16.10.2",
|
"@types/node": "^16.10.2",
|
||||||
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/pg": "^8.6.1",
|
"@types/pg": "^8.6.1",
|
||||||
"ava": "^3.15.0",
|
"ava": "^3.15.0",
|
||||||
"nodemon": "^2.0.13",
|
"nodemon": "^2.0.13",
|
||||||
|
6
packages/backend/src/apps/smtp/assets/favicon.svg
Normal file
6
packages/backend/src/apps/smtp/assets/favicon.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-label="Mail" role="img"
|
||||||
|
viewBox="0 0 512 512"><rect
|
||||||
|
width="512" height="512"
|
||||||
|
rx="15%"
|
||||||
|
fill="#328cff"/><path d="m250 186c-46 0-69 35-69 74 0 44 29 72 68 72 43 0 73-32 73-75 0-44-34-71-72-71zm-1-37c30 0 57 13 77 33 0-22 35-22 35 1v150c-1 10 10 16 16 9 25-25 54-128-14-187-64-56-149-47-195-15-48 33-79 107-49 175 33 76 126 99 182 76 28-12 41 26 12 39-45 19-168 17-225-82-38-68-36-185 67-248 78-46 182-33 244 32 66 69 62 197-2 246-28 23-71 1-71-32v-11c-20 20-47 32-77 32-57 0-108-51-108-108 0-58 51-110 108-110" fill="#fff"/></svg>
|
After Width: | Height: | Size: 573 B |
40
packages/backend/src/apps/smtp/index.ts
Normal file
40
packages/backend/src/apps/smtp/index.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import nodemailer from 'nodemailer';
|
||||||
|
import App from '../../models/app';
|
||||||
|
|
||||||
|
export default class SMTP {
|
||||||
|
client: any
|
||||||
|
connectionData: any
|
||||||
|
appData: any
|
||||||
|
|
||||||
|
constructor(connectionData: any) {
|
||||||
|
this.client = nodemailer.createTransport({
|
||||||
|
host: connectionData.host,
|
||||||
|
port: connectionData.port,
|
||||||
|
secure: connectionData.useTls,
|
||||||
|
auth: {
|
||||||
|
user: connectionData.username,
|
||||||
|
pass: connectionData.password,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
this.connectionData = connectionData;
|
||||||
|
this.appData = App.findOneByKey('smtp');
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyCredentials() {
|
||||||
|
await this.client.verify()
|
||||||
|
|
||||||
|
return {
|
||||||
|
screenName: this.connectionData.username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async isStillVerified() {
|
||||||
|
try {
|
||||||
|
await this.client.verify()
|
||||||
|
return true;
|
||||||
|
} catch(error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
200
packages/backend/src/apps/smtp/info.json
Normal file
200
packages/backend/src/apps/smtp/info.json
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
{
|
||||||
|
"name": "SMTP",
|
||||||
|
"key": "smtp",
|
||||||
|
"iconUrl": "{BASE_URL}/apps/smtp/assets/favicon.svg",
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp",
|
||||||
|
"primaryColor": "2DAAE1",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "host",
|
||||||
|
"label": "Host",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": "The host information Automatisch will connect to.",
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#host",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "username",
|
||||||
|
"label": "Email/Username",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": "Your SMTP login credentials.",
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#username",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "password",
|
||||||
|
"label": "Password",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#password",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "useTls",
|
||||||
|
"label": "Use TLS?",
|
||||||
|
"type": "boolean",
|
||||||
|
"required": false,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": false,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#use-tls",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "port",
|
||||||
|
"label": "Port",
|
||||||
|
"type": "integer",
|
||||||
|
"required": false,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": 25,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#port",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "fromEmail",
|
||||||
|
"label": "From Email",
|
||||||
|
"type": "string",
|
||||||
|
"required": false,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/smtp#from-email",
|
||||||
|
"clickToCopy": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"authenticationSteps": [
|
||||||
|
{
|
||||||
|
"step": 1,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "createConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "key",
|
||||||
|
"value": "{key}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"value": null,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "host",
|
||||||
|
"value": "{fields.host}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "username",
|
||||||
|
"value": "{fields.username}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "password",
|
||||||
|
"value": "{fields.password}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "useTLS",
|
||||||
|
"value": "{fields.useTls}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "port",
|
||||||
|
"value": "{fields.port}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fromEmail",
|
||||||
|
"value": "{fields.fromEmail}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{createConnection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"reconnectionSteps": [
|
||||||
|
{
|
||||||
|
"step": 1,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "resetConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "updateConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"value": null,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "host",
|
||||||
|
"value": "{fields.host}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "username",
|
||||||
|
"value": "{fields.username}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "password",
|
||||||
|
"value": "{fields.password}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "useTLS",
|
||||||
|
"value": "{fields.useTls}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "port",
|
||||||
|
"value": "{fields.port}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fromEmail",
|
||||||
|
"value": "{fields.fromEmail}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 3,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -18,7 +18,10 @@ const verifyConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
|||||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||||
|
|
||||||
connection = await connection.$query().patchAndFetch({
|
connection = await connection.$query().patchAndFetch({
|
||||||
data: verifiedCredentials,
|
data: {
|
||||||
|
...connection.data,
|
||||||
|
...verifiedCredentials
|
||||||
|
},
|
||||||
verified: true
|
verified: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
12
yarn.lock
12
yarn.lock
@@ -3180,6 +3180,13 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.33.tgz#24927446e8b7669d10abacedd16077359678f436"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.33.tgz#24927446e8b7669d10abacedd16077359678f436"
|
||||||
integrity sha512-5XmYX2GECSa+CxMYaFsr2mrql71Q4EvHjKS+ox/SiwSdaASMoBIWE6UmZqFO+VX1jIcsYLStI4FFoB6V7FeIYw==
|
integrity sha512-5XmYX2GECSa+CxMYaFsr2mrql71Q4EvHjKS+ox/SiwSdaASMoBIWE6UmZqFO+VX1jIcsYLStI4FFoB6V7FeIYw==
|
||||||
|
|
||||||
|
"@types/nodemailer@^6.4.4":
|
||||||
|
version "6.4.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/nodemailer/-/nodemailer-6.4.4.tgz#c265f7e7a51df587597b3a49a023acaf0c741f4b"
|
||||||
|
integrity sha512-Ksw4t7iliXeYGvIQcSIgWQ5BLuC/mljIEbjf615svhZL10PE9t+ei8O9gDaD3FPCasUJn9KTLwz2JFJyiiyuqw==
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/normalize-package-data@^2.4.0":
|
"@types/normalize-package-data@^2.4.0":
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
|
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
|
||||||
@@ -11099,6 +11106,11 @@ node-releases@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.0.tgz#67dc74903100a7deb044037b8a2e5f453bb05400"
|
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.0.tgz#67dc74903100a7deb044037b8a2e5f453bb05400"
|
||||||
integrity sha512-aA87l0flFYMzCHpTM3DERFSYxc6lv/BltdbRTOMZuxZ0cwZCD3mejE5n9vLhSJCN++/eOqr77G1IO5uXxlQYWA==
|
integrity sha512-aA87l0flFYMzCHpTM3DERFSYxc6lv/BltdbRTOMZuxZ0cwZCD3mejE5n9vLhSJCN++/eOqr77G1IO5uXxlQYWA==
|
||||||
|
|
||||||
|
nodemailer@6.7.0:
|
||||||
|
version "6.7.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.7.0.tgz#86614722c4e0c33d1b5b02aecb90d6d629932b0d"
|
||||||
|
integrity sha512-AtiTVUFHLiiDnMQ43zi0YgkzHOEWUkhDgPlBXrsDzJiJvB29Alo4OKxHQ0ugF3gRqRQIneCLtZU3yiUo7pItZw==
|
||||||
|
|
||||||
nodemon@^2.0.13:
|
nodemon@^2.0.13:
|
||||||
version "2.0.13"
|
version "2.0.13"
|
||||||
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.13.tgz#67d40d3a4d5bd840aa785c56587269cfcf5d24aa"
|
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.13.tgz#67d40d3a4d5bd840aa785c56587269cfcf5d24aa"
|
||||||
|
Reference in New Issue
Block a user