Feathers mailer service using
nodemailer
npm install feathers-mailer --save
If using a transport plugin, install the respective module.
transport
can be either SMTP options or a transport plugin with associated options.defaults
is an object that defines default values for mail options.
mailer.create
is a thin wrapper for transporter.sendMail
, accepting body
and returning err
and info
.
See here for possible fields of body
.
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 which can be run with npm run example
.
1.0.0
- Initial release
Copyright (c) 2016
Licensed under the MIT license.