feat: Implement smtp connection
This commit is contained in:
4
packages/backend/src/apps/smtp/assets/favicon.svg
Normal file
4
packages/backend/src/apps/smtp/assets/favicon.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<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: 580 B |
210
packages/backend/src/apps/smtp/auth/index.ts
Normal file
210
packages/backend/src/apps/smtp/auth/index.ts
Normal file
@@ -0,0 +1,210 @@
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
|
||||
export default {
|
||||
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: 'dropdown',
|
||||
required: false,
|
||||
readOnly: false,
|
||||
value: false,
|
||||
placeholder: null,
|
||||
description: null,
|
||||
docUrl: 'https://automatisch.io/docs/smtp#use-tls',
|
||||
clickToCopy: false,
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
label: 'No',
|
||||
value: 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}',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
};
|
13
packages/backend/src/apps/smtp/auth/is-still-verified.ts
Normal file
13
packages/backend/src/apps/smtp/auth/is-still-verified.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
try {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
22
packages/backend/src/apps/smtp/auth/verify-credentials.ts
Normal file
22
packages/backend/src/apps/smtp/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import nodemailer, { TransportOptions } from 'nodemailer';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const client = nodemailer.createTransport({
|
||||
host: $.auth.data.host,
|
||||
port: $.auth.data.port,
|
||||
secure: $.auth.data.useTls,
|
||||
auth: {
|
||||
user: $.auth.data.username,
|
||||
pass: $.auth.data.password,
|
||||
},
|
||||
} as TransportOptions);
|
||||
|
||||
await client.verify();
|
||||
|
||||
await $.auth.set({
|
||||
screenName: $.auth.data.username,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
13
packages/backend/src/apps/smtp/index.ts
Normal file
13
packages/backend/src/apps/smtp/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
|
||||
export default defineApp({
|
||||
name: 'SMTP',
|
||||
key: 'smtp',
|
||||
iconUrl: '{BASE_URL}/apps/smtp/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/connections/smtp',
|
||||
supportsConnections: true,
|
||||
baseUrl: '',
|
||||
apiBaseUrl: '',
|
||||
primaryColor: '2DAAE1',
|
||||
beforeRequest: [],
|
||||
});
|
@@ -16,6 +16,7 @@ class App {
|
||||
'scheduler',
|
||||
'slack',
|
||||
'twitter',
|
||||
'smtp',
|
||||
];
|
||||
|
||||
static async findAll(name?: string, stripFuncs = true): Promise<IApp[]> {
|
||||
|
Reference in New Issue
Block a user