Permalink
Browse files

:shipit:

  • Loading branch information...
1 parent 2d52613 commit 21c249d04ff2280f59eed46ce2cce8e9010d0f45 @ahdinosaur ahdinosaur committed Feb 29, 2016
Showing with 74 additions and 35 deletions.
  1. +55 −4 README.md
  2. +9 −11 examples/app.js
  3. +1 −1 package.json
  4. +8 −16 src/index.js
  5. +1 −3 test/index.test.js
View
@@ -2,19 +2,70 @@
[![Build Status](https://travis-ci.org/ahdinosaur/feathers-mailer.png?branch=master)](https://travis-ci.org/ahdinosaur/feathers-mailer)
-> Feathers mailer service
+> Feathers mailer service using [`nodemailer`](https://github.com/nodemailer/nodemailer)
-## About
+## Installation
+```shell
+npm install feathers-mailer --save
+```
+
+If using a [transport plugin](https://github.com/nodemailer/nodemailer#send-using-a-transport-plugin), install the respective module.
+
+
+## API
+
+### `import Mailer from 'feathers-mailer'`
+
+### `mailer = Mailer(transport, defaults)`
+
+- `transport` can be either [SMTP options](https://github.com/nodemailer/nodemailer#set-up-smtp) or a [transport plugin](https://github.com/nodemailer/nodemailer#send-using-a-transport-plugin) with associated options.
+- `defaults` is an object that defines default values for mail options.
+
+### `mailer.create(body, params)`
+
+`mailer.create` is a thin wrapper for [`transporter.sendMail`](https://github.com/nodemailer/nodemailer#sending-mail), accepting `body` and returning `err` and `info`.
+
+See [here](https://github.com/nodemailer/nodemailer#e-mail-message-fields) for possible fields of `body`.
+
+## Example
+
+```js
+import Mailer from 'feathers-mailer'
+import mandrill from 'nodemailer-mandrill-transport'
+
+// Register the service, see below for an example
+app.use('/mailer', Mailer(mandrill({
+ auth: {
+ apiKey: process.env.MANDRILL_API_KEY
+ }
+})));
+
+// Use the service
+var email = {
+ from: 'FROM_EMAIL',
+ to: 'TO_EMAIL',
+ subject: 'Sendgrid test',
+ html: 'This is the email body'
+};
+
+app.service('mailer').create(email).then(function (result) {
+ console.log('Sent email', result);
+}).catch(err => {
+ console.log(err);
+});
+```
+
+For a more complete example, see [examples/app](./examples/app.js) which can be run with `npm run example`.
## Changelog
-__0.1.0__
+__1.0.0__
- Initial release
## License
-Copyright (c) 2015
+Copyright (c) 2016
Licensed under the [MIT license](LICENSE).
View
@@ -1,16 +1,14 @@
-import mandrillTransport from 'nodemailer-mandrill-transport'
-import createMailer from '../src'
+import mandrill from 'nodemailer-mandrill-transport'
+import Mailer from '../src'
import feathers from 'feathers'
import rest from 'feathers-rest';
import bodyParser from 'body-parser';
-const mailerService = createMailer({
- Model: mandrillTransport({
- auth: {
- apiKey: process.env.MANDRILL_API_KEY || 'notakey'
- }
- })
-});
+const mailer = Mailer(mandrill({
+ auth: {
+ apiKey: process.env.MANDRILL_API_KEY || 'notakey'
+ }
+}));
// Create a feathers instance.
var app = feathers()
@@ -20,7 +18,7 @@ var app = feathers()
.use(bodyParser.json())
// Turn on URL-encoded parser for REST services
.use(bodyParser.urlencoded({extended: true}))
- .use('/mails', mailerService);
+ .use('/mailer', mailer);
// A basic error handler, just like Express
app.use(function(error, req, res, next){
@@ -30,4 +28,4 @@ app.use(function(error, req, res, next){
// Start the server
module.exports = app.listen(3030);
-console.log('feathers-mailer service running on 127.0.0.1:3030/mails');
+console.log('feathers-mailer service running on 127.0.0.1:3030/mailer');
View
@@ -1,7 +1,7 @@
{
"name": "feathers-mailer",
"description": "Feathers mailer service",
- "version": "0.0.0",
+ "version": "1.0.0",
"homepage": "https://github.com/ahdinosaur/feathers-mailer",
"main": "lib/",
"keywords": [
View
@@ -8,21 +8,13 @@ import Mailer from 'nodemailer';
const debug = makeDebug('feathers-mailer');
class Service {
- constructor (options) {
- debug('constructor', options);
- if (!options) {
- throw new Error('feathers-mailer: constructor `options` must be provided');
+ constructor (transport, defaults) {
+ debug('constructor', transport);
+ if (!transport) {
+ throw new Error('feathers-mailer: constructor `transport` must be provided');
}
- if (!options.Model) {
- throw new Error('feathers-mailer: constructor `options.Model` must be provided');
- }
-
- this.Model = Mailer.createTransport(
- options.Model,
- options.defaults
- );
- this.id = options.id || 'id';
+ this.transporter = Mailer.createTransport(transport, defaults);
}
extend (obj) {
@@ -33,12 +25,12 @@ class Service {
debug('create', body, params);
// TODO maybe body should be text/html field
// and params is rest of options
- this.Model.sendMail(body, cb);
+ this.transporter.sendMail(body, cb);
}
}
-export default function init(options) {
- return new Service(options);
+export default function init(transport, defaults) {
+ return new Service(transport, defaults);
}
init.Service = Service;
View
@@ -10,9 +10,7 @@ describe('feathers-mailer', () => {
it('basic functionality', done => {
assert.equal(typeof createMailer, 'function', 'exports function');
- const mailer = createMailer({
- Model: stubTransport()
- });
+ const mailer = createMailer(stubTransport());
let mailData = {
from: '"Alice" <alice@example.com>',
to: ['bob@example.com', '"Carol" <carol@example.com>'],

0 comments on commit 21c249d

Please sign in to comment.