working initial commit
commit
7e3eb693db
|
@ -0,0 +1 @@
|
|||
/node_modules/
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
import gmail from 'gmail-send'
|
||||
import ses from 'node-ses'
|
||||
import {stringify as nice} from 'yaml'
|
||||
|
||||
const create = { gmail:gmail,ses:ses }
|
||||
|
||||
class Email {
|
||||
constructor(opts) {
|
||||
this._pkg = {
|
||||
subject: opts.subject || 'notification',
|
||||
to: opts.to,
|
||||
label: opts.label
|
||||
}
|
||||
Object.assign(this._pkg,opts.credentials)
|
||||
this.smtp = opts.smtp || 'gmail'
|
||||
this._send = create[this.smtp](this.pkg)
|
||||
}
|
||||
|
||||
async send (msg='', opts={}) {
|
||||
const pkg = Object.assign({},this._pkg,opts)
|
||||
if (typeof msg === 'string') { pkg.subject = msg; pkg.text = msg }
|
||||
else {
|
||||
pkg.subject = msg.msg || msg.message || msg.subject
|
||||
pkg.text = msg.text || nice(msg)
|
||||
pkg.html = msg.html
|
||||
pkg.files = msg.files
|
||||
}
|
||||
if (!pkg.to) return {error:'no recipients'}
|
||||
try {
|
||||
let res = await this._send(pkg)
|
||||
return res
|
||||
} catch (err) {
|
||||
return {error:err}
|
||||
}
|
||||
}
|
||||
|
||||
setOpts (opts={}) {
|
||||
Object.assign(this.pkg,opts)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Email
|
||||
export { Email as Service }
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "@uci-utils/notify-email-plugin",
|
||||
"version": "0.1.5",
|
||||
"description": "email uci notify plugin",
|
||||
"main": "email.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"notification",
|
||||
"email"
|
||||
],
|
||||
"author": "codecoots",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"gmail-send": "^1.8.10",
|
||||
"node-ses": "^3.0.2",
|
||||
"yaml": "^1.10.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue