Merge remote-tracking branch 'xo-server-transport-email/master'
This commit is contained in:
commit
9ca531541d
65
packages/xo-server-transport-email/.editorconfig
Normal file
65
packages/xo-server-transport-email/.editorconfig
Normal file
@ -0,0 +1,65 @@
|
||||
# http://EditorConfig.org
|
||||
#
|
||||
# Julien Fontanet's configuration
|
||||
# https://gist.github.com/julien-f/8096213
|
||||
|
||||
# Top-most EditorConfig file.
|
||||
root = true
|
||||
|
||||
# Common config.
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# CoffeeScript
|
||||
#
|
||||
# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md
|
||||
[*.{,lit}coffee]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# Markdown
|
||||
[*.{md,mdwn,mdown,markdown}]
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
|
||||
# Package.json
|
||||
#
|
||||
# This indentation style is the one used by npm.
|
||||
[package.json]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# Pug (Jade)
|
||||
[*.{jade,pug}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# JavaScript
|
||||
#
|
||||
# Two spaces seems to be the standard most common style, at least in
|
||||
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
|
||||
[*.{js,jsx,ts,tsx}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# Less
|
||||
[*.less]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# Sass
|
||||
#
|
||||
# Style used for http://libsass.com
|
||||
[*.s[ac]ss]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# YAML
|
||||
#
|
||||
# Only spaces are allowed.
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
indent_style = space
|
9
packages/xo-server-transport-email/.gitignore
vendored
Normal file
9
packages/xo-server-transport-email/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/coverage/
|
||||
/dist/
|
||||
/node_modules/
|
||||
|
||||
npm-debug.log
|
||||
npm-debug.log.*
|
||||
pnpm-debug.log
|
||||
pnpm-debug.log.*
|
||||
yarn-error.log
|
24
packages/xo-server-transport-email/.npmignore
Normal file
24
packages/xo-server-transport-email/.npmignore
Normal file
@ -0,0 +1,24 @@
|
||||
/benchmark/
|
||||
/benchmarks/
|
||||
*.bench.js
|
||||
*.bench.js.map
|
||||
|
||||
/examples/
|
||||
example.js
|
||||
example.js.map
|
||||
*.example.js
|
||||
*.example.js.map
|
||||
|
||||
/fixture/
|
||||
/fixtures/
|
||||
*.fixture.js
|
||||
*.fixture.js.map
|
||||
*.fixtures.js
|
||||
*.fixtures.js.map
|
||||
|
||||
/test/
|
||||
/tests/
|
||||
*.spec.js
|
||||
*.spec.js.map
|
||||
|
||||
__snapshots__/
|
9
packages/xo-server-transport-email/.travis.yml
Normal file
9
packages/xo-server-transport-email/.travis.yml
Normal file
@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
- 6
|
||||
- 4
|
||||
|
||||
# Use containers.
|
||||
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
sudo: false
|
50
packages/xo-server-transport-email/README.md
Normal file
50
packages/xo-server-transport-email/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# xo-server-transport-email [](https://travis-ci.org/vatesfr/xo-server-transport-email)
|
||||
|
||||
> xo-server plugin to send emails
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/xo-server-transport-email):
|
||||
|
||||
```
|
||||
> npm install --global xo-server-transport-email
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Like all other xo-server plugins, it can be configured directly via
|
||||
the web iterface, see [the plugin documentation](https://xen-orchestra.com/docs/plugins.html).
|
||||
|
||||
## Development
|
||||
|
||||
```
|
||||
# Install dependencies
|
||||
> npm install
|
||||
|
||||
# Run the tests
|
||||
> npm test
|
||||
|
||||
# Continuously compile
|
||||
> npm run dev
|
||||
|
||||
# Continuously run the tests
|
||||
> npm run dev-test
|
||||
|
||||
# Build for production (automatically called by npm install)
|
||||
> npm run build
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are *very* welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xo-server-transport-email/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
AGPL3 © [Vates SAS](http://vates.fr)
|
91
packages/xo-server-transport-email/package.json
Normal file
91
packages/xo-server-transport-email/package.json
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "xo-server-transport-email",
|
||||
"version": "0.3.2",
|
||||
"license": "AGPL-3.0",
|
||||
"description": "xo-server plugin to send emails",
|
||||
"keywords": [
|
||||
"email",
|
||||
"mail",
|
||||
"orchestra",
|
||||
"xen",
|
||||
"xen-orchestra",
|
||||
"xo-server"
|
||||
],
|
||||
"homepage": "https://github.com/vatesfr/xo-server-transport-email",
|
||||
"bugs": "https://github.com/vatesfr/xo-server-transport-email/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xo-server-transport-email"
|
||||
},
|
||||
"author": {
|
||||
"name": "Julien Fontanet",
|
||||
"email": "julien.fontanet@isonoe.net"
|
||||
},
|
||||
"preferGlobal": false,
|
||||
"main": "dist/",
|
||||
"bin": {},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.4",
|
||||
"nodemailer": "2.6.4",
|
||||
"nodemailer-markdown": "^1.0.1",
|
||||
"promise-toolbox": "^0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.18.0",
|
||||
"babel-eslint": "^7.1.1",
|
||||
"babel-plugin-lodash": "^3.2.11",
|
||||
"babel-preset-env": "^1.1.8",
|
||||
"babel-preset-stage-3": "^6.17.0",
|
||||
"cross-env": "^3.1.4",
|
||||
"dependency-check": "^2.7.0",
|
||||
"husky": "^0.12.0",
|
||||
"jest": "^18.1.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"standard": "^8.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||
"commit-msg": "npm test",
|
||||
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
|
||||
"dev-test": "jest --bail --watch",
|
||||
"posttest": "standard && dependency-check ./package.json",
|
||||
"prebuild": "rimraf dist/",
|
||||
"predev": "npm run prebuild",
|
||||
"prepublish": "npm run build",
|
||||
"test": "jest"
|
||||
},
|
||||
"babel": {
|
||||
"plugins": [
|
||||
"lodash"
|
||||
],
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"node": 4
|
||||
}
|
||||
}
|
||||
],
|
||||
"stage-3"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"testPathDirs": [
|
||||
"<rootDir>/src"
|
||||
],
|
||||
"testRegex": "\\.spec\\.js$"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
],
|
||||
"parser": "babel-eslint"
|
||||
}
|
||||
}
|
193
packages/xo-server-transport-email/src/index.js
Normal file
193
packages/xo-server-transport-email/src/index.js
Normal file
@ -0,0 +1,193 @@
|
||||
import { bind } from 'lodash'
|
||||
import { createTransport } from 'nodemailer'
|
||||
import { markdown as nodemailerMarkdown } from 'nodemailer-markdown'
|
||||
import { promisify } from 'promise-toolbox'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const markdownCompiler = nodemailerMarkdown()
|
||||
|
||||
const logAndRethrow = error => {
|
||||
console.error('[WARN] plugin transport-email:', error && error.stack || error)
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export const configurationSchema = {
|
||||
type: 'object',
|
||||
|
||||
properties: {
|
||||
from: {
|
||||
type: 'object',
|
||||
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'human readable name of the sender'
|
||||
},
|
||||
address: {
|
||||
type: 'string',
|
||||
description: 'email address of the sender'
|
||||
}
|
||||
},
|
||||
|
||||
additionalProperties: false,
|
||||
required: ['address']
|
||||
},
|
||||
|
||||
transport: {
|
||||
type: 'object',
|
||||
|
||||
properties: {
|
||||
host: {
|
||||
type: 'string',
|
||||
description: 'hostname or IP address of the SMTP server'
|
||||
},
|
||||
port: {
|
||||
type: 'integer',
|
||||
description: 'port of the SMTP server (defaults to 25 or 465)'
|
||||
},
|
||||
secure: {
|
||||
type: 'boolean',
|
||||
description: 'whether the connection should use SSL'
|
||||
},
|
||||
ignoreUnauthorized: {
|
||||
type: 'boolean',
|
||||
description: 'ignore certificates error (e.g. self-signed certificate)'
|
||||
},
|
||||
|
||||
// FIXME: xo-web does not support edition of too nested
|
||||
user: {
|
||||
type: 'string',
|
||||
description: 'name to use to authenticate'
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
description: 'password to use to authenticate'
|
||||
}
|
||||
// properties.
|
||||
// auth: {
|
||||
// type: 'object',
|
||||
|
||||
// properties: {
|
||||
// user: {
|
||||
// type: 'string',
|
||||
// description: 'name to use to authenticate'
|
||||
// },
|
||||
// pass: {
|
||||
// type: 'string',
|
||||
// description: 'password to use to authenticate'
|
||||
// }
|
||||
// },
|
||||
|
||||
// additionalProperties: false,
|
||||
// required: ['user', 'pass']
|
||||
// }
|
||||
},
|
||||
|
||||
additionalProperties: false,
|
||||
required: ['host']
|
||||
}
|
||||
},
|
||||
|
||||
additionalProperties: false,
|
||||
required: ['from', 'transport']
|
||||
}
|
||||
|
||||
export const testSchema = {
|
||||
type: 'object',
|
||||
|
||||
properties: {
|
||||
to: {
|
||||
type: 'string',
|
||||
description: 'recipient of the test mail'
|
||||
}
|
||||
},
|
||||
|
||||
additionalProperties: false,
|
||||
required: ['to']
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class TransportEmailPlugin {
|
||||
constructor ({ xo }) {
|
||||
this._sendEmail = bind(this._sendEmail, this)
|
||||
this._set = bind(xo.defineProperty, xo)
|
||||
this._unset = null
|
||||
|
||||
// Defined in configure().
|
||||
this._conf = null
|
||||
this._send = null
|
||||
}
|
||||
|
||||
configure ({
|
||||
transport: {
|
||||
ignoreUnauthorized,
|
||||
password,
|
||||
user,
|
||||
...transportConf
|
||||
},
|
||||
...conf
|
||||
}) {
|
||||
if (ignoreUnauthorized != null) {
|
||||
(
|
||||
transportConf.tls ||
|
||||
(transportConf.tls = {})
|
||||
).rejectUnauthorized = !ignoreUnauthorized
|
||||
}
|
||||
|
||||
if (user != null && password != null) {
|
||||
transportConf.auth = { user, pass: password }
|
||||
}
|
||||
|
||||
const transport = createTransport(transportConf)
|
||||
transport.use('compile', markdownCompiler)
|
||||
|
||||
this._conf = conf
|
||||
this._send = promisify(transport.sendMail, transport)
|
||||
}
|
||||
|
||||
load () {
|
||||
this._unset = this._set('sendEmail', this._sendEmail)
|
||||
}
|
||||
|
||||
unload () {
|
||||
this._unset()
|
||||
}
|
||||
|
||||
test ({to}) {
|
||||
return this._sendEmail({
|
||||
to,
|
||||
subject: '[Xen Orchestra] Test of transport-email plugin',
|
||||
markdown: `Hi there,
|
||||
|
||||
The transport-email plugin for Xen Orchestra server seems to be working fine, nicely done :)`
|
||||
})
|
||||
}
|
||||
|
||||
_sendEmail ({
|
||||
from = this._conf.from,
|
||||
to, cc, bcc,
|
||||
subject,
|
||||
markdown,
|
||||
attachments
|
||||
}) {
|
||||
// TODO: handle errors
|
||||
return this._send({
|
||||
from,
|
||||
to,
|
||||
cc,
|
||||
bcc,
|
||||
subject,
|
||||
markdown,
|
||||
attachments
|
||||
}).catch(logAndRethrow)
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export default opts => new TransportEmailPlugin(opts)
|
3578
packages/xo-server-transport-email/yarn.lock
Normal file
3578
packages/xo-server-transport-email/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user