@abhishekdeb/ezmailer 中文文档教程
ezMailer v0.1.1
开箱即用的流行 nodejs 电子邮件系统(NodeMailer、Sendgrid、MailGun)的电子邮件包装器
ezMailer 是 node JS 生态系统的开箱即用的电子邮件系统包装器。 ezMailer 背后的主要原则是从开发人员那里抽象出维护一个(或多个)电子邮件系统的细微差别。
哦,它也有全面的模板支持! 耶!
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 相当简约配置,对于您使用的任何电子邮件系统都保持不变。
// 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]'
}
}
};
您将在启动时将此配置提供给 ezmailer 的初始化。
// 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 需要一个配置文件,其中将包含您用于 NodeMailer、sendgrid 等的 smtp 凭据……
请使用上面的配置文件。
- Create a Config File:
// config.mail.js
'use strict';
module.exports = {
templatePath: './',
mailer: {
service: 'Gmail',
user: 'sample.user@gmail.com',
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: 'from@gmail.com',
to: 'to@gmail.com',
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);
}
);
更多例子和用法请参考(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
源码不错简单的。 主要的 index.js 文件负责服务发现和选择。 服务在“services”目录中定义。 如果您需要添加新的电子邮件提供商,如 nodemailer 或 sendgrid,请在 services 中创建一个新文件夹,它将自动注册。
要开始使用扩展程序,请复制粘贴现有服务并对其进行编辑。
注释
- extension Directory name and ezmailer.use(config, <name>) should be identical.
- All new extensions must support the generic config file
用法
- 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 – vikz91.deb@gmail.com
分布式在麻省理工学院的许可下。 有关详细信息,请参阅 LICENSE
。
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
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: 'sample.user@gmail.com',
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: 'from@gmail.com',
to: 'to@gmail.com',
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 – vikz91.deb@gmail.com
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