@abhishekdeb/ezmailer 中文文档教程

发布于 6年前 浏览 21 项目主页 更新于 3年前

ezMailer v0.1.1

开箱即用的流行 nodejs 电子邮件系统(NodeMailer、Sendgrid、MailGun)的电子邮件包装器

NPM 版本构建状态下载统计

ezMailer 是 node JS 生态系统的开箱即用的电子邮件系统包装器。 ezMailer 背后的主要原则是从开发人员那里抽象出维护一个(或多个)电子邮件系统的细微差别。

哦,它也有全面的模板支持! 耶!

Requirements

  1. node >= 8
  2. 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 凭据……
请使用上面的配置文件。

  1. Create a Config File:
// config.mail.js
'use strict';

module.exports = {
  templatePath: './',

  mailer: {
    service: 'Gmail',
    user: 'sample.user@gmail.com',
    pass: 'sample.password'
  }
};
  1. 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');
  1. 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 中创建一个新文件夹,它将自动注册。
要开始使用扩展程序,请复制粘贴现有服务并对其进行编辑。
注释

  1. extension Directory name and ezmailer.use(config, <name>) should be identical.
  2. All new extensions must support the generic config file

用法

  1. Create new entry in your email config.
  2. Copy Paste & Edit / Create new folder insideservices directory : Services/customProvider
  3. Edit/ Write index.js to first read the config file and then eventually send same reply.
  4. Write test cases for the extension in spec.js inside the same extension directory.
  5. Get reviewed by peer.

Meta

Abhishek Deb – @vikz91 – vikz91.deb@gmail.com

分布式在麻省理工学院的许可下。 有关详细信息,请参阅 LICENSE

https://github.com/vikz91

Contributors

  1. VikZ91 - Base System
  2. EranGoldman - Adding Mailgun

Contributing

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Bucket List

  1. ~Seperate Config File System~
  2. ~Update ReadMe~
  3. ~Seperate Npm Package (from generator-restgoose)~
  4. SoC Refactoring <- going on
  5. Extensive Testing
  6. Write Test Cases using Karma
  7. Write Functions to add custom email transport
  8. Add to Travis / Circle
  9. Adding Attachments
  10. Subject Template
  11. Attachments
  12. CC, BCC
  13. Receive EMAIL Notification Hook
  14. Adding Support for MailChimp

ezMailer v0.1.1

Out of the box Email wrapper for popular nodejs email systems ( NodeMailer, Sendgrid, MailGun)

NPM VersionBuild StatusDownloads Stats

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

  1. node >= 8
  2. 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.

  1. Create a Config File:
// config.mail.js
'use strict';

module.exports = {
  templatePath: './',

  mailer: {
    service: 'Gmail',
    user: 'sample.user@gmail.com',
    pass: 'sample.password'
  }
};
  1. 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');
  1. 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

  1. extension Directory name and ezmailer.use(config, <name>) should be identical.
  2. All new extensions must support the generic config file

Usage

  1. Create new entry in your email config.
  2. Copy Paste & Edit / Create new folder insideservices directory : Services/customProvider
  3. Edit/ Write index.js to first read the config file and then eventually send same reply.
  4. Write test cases for the extension in spec.js inside the same extension directory.
  5. Get reviewed by peer.

Meta

Abhishek Deb – @vikz91 – vikz91.deb@gmail.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/vikz91

Contributors

  1. VikZ91 - Base System
  2. EranGoldman - Adding Mailgun

Contributing

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Bucket List

  1. ~Seperate Config File System~
  2. ~Update ReadMe~
  3. ~Seperate Npm Package (from generator-restgoose)~
  4. SoC Refactoring <- going on
  5. Extensive Testing
  6. Write Test Cases using Karma
  7. Write Functions to add custom email transport
  8. Add to Travis / Circle
  9. Adding Attachments
  10. Subject Template
  11. Attachments
  12. CC, BCC
  13. Receive EMAIL Notification Hook
  14. Adding Support for MailChimp
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文