Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kenote/mailer-helper
Mailer's Helper.
https://github.com/kenote/mailer-helper
assistant helper mjml nodemailer typescript
Last synced: 3 days ago
JSON representation
Mailer's Helper.
- Host: GitHub
- URL: https://github.com/kenote/mailer-helper
- Owner: kenote
- License: mit
- Created: 2018-12-18T09:08:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-24T03:50:09.000Z (over 4 years ago)
- Last Synced: 2024-12-19T19:23:15.114Z (about 1 month ago)
- Topics: assistant, helper, mjml, nodemailer, typescript
- Language: TypeScript
- Size: 92.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mailer-helper
Mailer's Helper.
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Gratipay][licensed-image]][licensed-url]## Installation
```bash
$ npm install kenote-mailer-helper
#
$ yarn add kenote-mailer-helper
```## Usages
`mailer.ts`
```ts
import { Mailer, Setting } from 'kenote-mailer-helper'
import * as Mail from 'nodemailer/lib/mailer'@Setting({
smtpOptions: {
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: '[email protected]',
pass: 'aPxRSFBXbM7dseEwKK'
}
},
asyncRetryOptions: {
times: 3,
interval: 200
},
mailDir: 'mails',
renderString: nunjucks.renderString
})
class NodeMailer extends Mailer {}/**
* 发送邮件选项
* @ from -- 发件人
* 格式 -- 发件人名称 <发件人邮箱地址>
* @ to -- 收件人
* 格式 -- 收件人 <收件人邮箱地址>
* 多个收件人用逗号分割
* @ cc -- 抄送,可选项
* 格式 -- 与收件人相同
* @ bcc -- 密送,可选项
* 格式 -- 与收件人相同
* @ subject -- 标题
* 格式 -- 字符串
* @ text -- 正文,文本形式
* 格式 -- 字符串
* @ html -- 正文,HTML形式
* 格式 -- HTML格式
* @ attachments -- 附件,可选项
* 格式 -- 数组
* [
* {
* filename: 'README.md',
* path: path.resolve(process.cwd(), 'README.md'),
* cid: '00000001'
* },
* {
* filename: 'README.md',
* content: '发送内容',
* cid: '00000002'
* }
* ]
**/
const mail: Mail = {
from: '[email protected]',
to: '[email protected]',
subject: 'Ethereal Email',
text: 'Ethereal Email.'
}const nodeMailer: NodeMailer = new NodeMailer()
// asyncSend
nodeMailer.asyncSend(mail)// renderMail
nodeMailer.renderMail('email_verify.mjml', {})// sendMail
nodeMailer.sendMail('email_verify.mjml', mail, {})
````email_verify.mjml`
```xml
{{ site_name }}邮箱验证
亲爱的 {{ username }}:
欢迎申请{{ site_name }}服务!
你的{{ site_name }}帐号是: {{ username }}
请点击下面的链接完成邮箱验证:
{{ email_verify_url }}
如果以上链接无法点击,请将该链接复制到浏览器(如 Chrome )的地址栏中访问,也可以成功完成邮箱验证!
1. 为了保障您账号的安全性, 请在{{ timeout }}小时内完成验证, 此链接将在您激活过一次后失效!
2. 如您没有注册过{{ site_name }}账号, 请您忽略此邮件, 由此给您带来的不便敬请谅解。
- {{ site_name }}
(这是一封自动产生的Email,请勿回复)
```
## License
this repo is released under the [MIT License](https://github.com/kenote/mailer-helper/blob/master/LICENSE).
[npm-image]: https://img.shields.io/npm/v/kenote-mailer-helper.svg
[npm-url]: https://www.npmjs.com/package/kenote-mailer-helper
[downloads-image]: https://img.shields.io/npm/dm/kenote-mailer-helper.svg
[downloads-url]: https://www.npmjs.com/package/kenote-mailer-helper
[travis-image]: https://travis-ci.com/kenote/mailer-helper.svg?branch=master
[travis-url]: https://travis-ci.com/kenote/mailer-helper
[licensed-image]: https://img.shields.io/badge/license-MIT-blue.svg
[licensed-url]: https://github.com/kenote/mailer-helper/blob/master/LICENSE