@abhishekdeb/ezmailer
v0.1.1
Published
Out of the box Email wrapper for popular nodejs email systems
Downloads
13
Maintainers
Readme
ezMailer v0.1.1
Out of the box Email wrapper for popular nodejs email systems ( NodeMailer, Sendgrid, MailGun)
ezMailer is an out-of-the-box email system wrapper for node JS ecosystem. The Main principle behind ezMailer is to abstract the nuances of maintaining an (or more) email system(s) from the developer.
Oh, and it has full blown templating support as well! Yay!
Requirements
- node >= 8
- npm >= 5
Features
- Simple and ready to use, yet Powerful Email API
- Nodemailer, email-templates, sendgrid, Mailgun integrated
- Examples incuded
- Config style setup
- Promisified API
- Used in generator-restgoose
- Extensible
- Much more to come ...
Installation
npm: npm i @abhishekdeb/ezmailer --save
yarn: yarn add @abhishekdeb/ezmailer
Setup
ezMailer has fairly minimalistic config, which stays same for any email system you work with.
// config.mail.js
'use strict';
module.exports = {
templatePath: './',
services: {
nodemailer: {
provider: 'Gmail', //yahoo, etc.
user: '[Username]@gmail.com',
pass: '[Your_Password]'
},
sendgrid: '[Your_SendGrid_Key]',
mailgun: {
apiKey: '[Your_Mailgun_key]',
domain: '[Your_website_domain]'
}
}
};
You will feed this config to initialization of ezmailer on startup.
// app.js (or any entry point of the app)
let config = require('./config.mail.js'); // the above configuration
//Load ezmailer with the config's email section that corresponds to ezmailer
let ezmailer = require('ezmailer');
ezmailer.use(config, 'nodemailer'); //nodemailer / sendgrid / mailgun
Usage example
ezMailer needs a config file which will contain your smtp credentials for NodeMailer, sendgrid, etc...
Please use a config file like above.
- Create a Config File:
// config.mail.js
'use strict';
module.exports = {
templatePath: './',
mailer: {
service: 'Gmail',
user: '[email protected]',
pass: 'sample.password'
}
};
- Require this config and pass it to ezmailer with default service
//app.js
'use strict';
let ezmailer = require('ezmailer');
ezmailer.use(require('./config.mail'), 'nodemailer');
- Load up email options and sendMail
//service.sample.js
let mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sample Basic ezmailer test',
body: {
text: 'This is basic ezmailer test. ',
html: '<h1>This is <u>Basic</u> <b><i>ez</i>Mailer<b> test.'
}
};
//Send the mail. sendMail returns a promise.
ezmailer.sendMail(mailOptions).then(
data => {
console.log('Email has been sent : ', data);
},
err => {
console.log('Email could not be sent : ', err);
}
);
For more examples and usage, please refer to the (Wiki)wiki.
Release History
- 0.1.1
- Major Revamp of architecture
- Upgraded all packages
- Faster, Stronger, Sharper
- 0.0.2
- Small Bug FIxes
- 0.0.1
- Initial Release
- Templating System Integrated
Extension
The source is pretty simple. The main index.js file is responsible for service discovery and selection. The Services are defined in 'services' directory. If you need to add a new email provider like nodemailer or sendgrid, create a new folder inside services and it will be automatically registered.
To get started with extensions, copy paste an existing service and edit through it.
NOTES
- extension Directory name and ezmailer.use(config, <name>) should be identical.
- All new extensions must support the generic config file
Usage
- Create new entry in your email config.
- Copy Paste & Edit / Create new folder insideservices directory :
Services/customProvider
- Edit/ Write
index.js
to first read the config file and then eventually send same reply. - Write test cases for the extension in spec.js inside the same extension directory.
- Get reviewed by peer.
Meta
Abhishek Deb – @vikz91 – [email protected]
Distributed under the MIT license. See LICENSE
for more information.
Contributors
- VikZ91 - Base System
- EranGoldman - Adding Mailgun
Contributing
- Fork it (https://github.com/yourname/yourproject/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Bucket List
- ~Seperate Config File System~
- ~Update ReadMe~
- ~Seperate Npm Package (from generator-restgoose)~
- SoC Refactoring <- going on
- Extensive Testing
- Write Test Cases using Karma
- Write Functions to add custom email transport
- Add to Travis / Circle
- Adding Attachments
- Subject Template
- Attachments
- CC, BCC
- Receive EMAIL Notification Hook
- Adding Support for MailChimp