mirror of https://github.com/nocodb/nocodb
Browse Source
* fix: remove the old implementation Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com> * feat: add new ses implementation Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com> * feat: add SESPluginConfig Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com> * fix: add ses old implementation back for migration Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com> * feat: add ses migration source Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com> * chore: add deprecation message Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>pull/970/head
WK WONG
3 years ago
committed by
GitHub
7 changed files with 208 additions and 3 deletions
@ -0,0 +1,36 @@
|
||||
import Knex from 'knex'; |
||||
import ses from '../plugins/ses'; |
||||
|
||||
const up = async (knex: Knex) => { |
||||
await knex('nc_plugins').del().where({title: "SES"}); |
||||
}; |
||||
|
||||
const down = async (knex: Knex) => { |
||||
await knex('nc_plugins').insert([ |
||||
ses |
||||
]); |
||||
}; |
||||
|
||||
export { up, down }; |
||||
|
||||
/** |
||||
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||
* |
||||
* @author Wing-Kam Wong <wingkwong.code@gmail.com> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
@ -0,0 +1,73 @@
|
||||
import { IEmailAdapter } from 'nc-plugin'; |
||||
import nodemailer from 'nodemailer'; |
||||
import Mail from 'nodemailer/lib/mailer'; |
||||
import AWS from 'aws-sdk'; |
||||
import { XcEmail } from '../../interface/IEmailAdapter'; |
||||
|
||||
export default class SES implements IEmailAdapter { |
||||
private transporter: Mail; |
||||
private input: any; |
||||
|
||||
constructor(input: any) { |
||||
this.input = input; |
||||
} |
||||
|
||||
public async init(): Promise<any> { |
||||
const sesOptions: any = { |
||||
accessKeyId: this.input.access_key, |
||||
secretAccessKey: this.input.access_secret, |
||||
region: this.input.region |
||||
}; |
||||
|
||||
this.transporter = nodemailer.createTransport({ |
||||
SES: new AWS.SES(sesOptions) |
||||
}); |
||||
} |
||||
|
||||
public async mailSend(mail: XcEmail): Promise<any> { |
||||
if (this.transporter) { |
||||
this.transporter.sendMail({ ...mail, from: this.input.from }, (err, info) => { |
||||
if (err) { |
||||
console.log(err); |
||||
} else { |
||||
console.log('Message sent: ' + info.response); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
public async test(): Promise<boolean> { |
||||
try { |
||||
await this.mailSend({ |
||||
to: this.input.from, |
||||
subject: 'Test email', |
||||
html: 'Test email' |
||||
} as any); |
||||
return true |
||||
} catch (e) { |
||||
throw e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||
* |
||||
* @author Wing-Kam Wong <wingkwong.code@gmail.com> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
@ -0,0 +1,18 @@
|
||||
import { IEmailAdapter, XcEmailPlugin } from 'nc-plugin'; |
||||
|
||||
import SES from './SES'; |
||||
|
||||
class SESPlugin extends XcEmailPlugin { |
||||
private static storageAdapter: SES; |
||||
|
||||
public getAdapter(): IEmailAdapter { |
||||
return SESPlugin.storageAdapter; |
||||
} |
||||
|
||||
public async init(config: any): Promise<any> { |
||||
SESPlugin.storageAdapter = new SES(config); |
||||
await SESPlugin.storageAdapter.init(); |
||||
} |
||||
} |
||||
|
||||
export default SESPlugin; |
@ -0,0 +1,69 @@
|
||||
import { XcActionType, XcType } from 'nc-common'; |
||||
import { XcPluginConfig } from 'nc-plugin'; |
||||
|
||||
import SESPlugin from './SESPlugin'; |
||||
|
||||
const config: XcPluginConfig = { |
||||
builder: SESPlugin, |
||||
title: 'SES', |
||||
version: '0.0.1', |
||||
logo: 'plugins/aws.png', |
||||
description: 'Amazon Simple Email Service (SES) is a cost-effective, flexible, and scalable email service that enables developers to send mail from within any application.', |
||||
price: 'Free', |
||||
tags: 'Email', |
||||
category: 'Email', |
||||
inputs: { |
||||
title: 'Configure Amazon Simple Email Service (SES)', |
||||
items: [ |
||||
{ |
||||
key: 'from', |
||||
label: 'From', |
||||
placeholder: 'From', |
||||
type: XcType.SingleLineText, |
||||
required: true |
||||
}, |
||||
{ |
||||
key: 'region', |
||||
label: 'Region', |
||||
placeholder: 'Region', |
||||
type: XcType.SingleLineText, |
||||
required: true |
||||
}, |
||||
{ |
||||
key: 'access_key', |
||||
label: 'Access Key', |
||||
placeholder: 'Access Key', |
||||
type: XcType.SingleLineText, |
||||
required: true |
||||
}, |
||||
{ |
||||
key: 'access_secret', |
||||
label: 'Access Secret', |
||||
placeholder: 'Access Secret', |
||||
type: XcType.Password, |
||||
required: true |
||||
} |
||||
], |
||||
actions: [ |
||||
{ |
||||
label: 'Test', |
||||
placeholder: 'Test', |
||||
key: 'test', |
||||
actionType: XcActionType.TEST, |
||||
type: XcType.Button |
||||
}, |
||||
{ |
||||
label: 'Save', |
||||
placeholder: 'Save', |
||||
key: 'save', |
||||
actionType: XcActionType.SUBMIT, |
||||
type: XcType.Button |
||||
} |
||||
], |
||||
msgOnInstall: |
||||
'Successfully installed and email notification will use Amazon SES', |
||||
msgOnUninstall: '' |
||||
} |
||||
}; |
||||
|
||||
export default config; |
Loading…
Reference in new issue