Skip to content

Latest commit

 

History

History
161 lines (116 loc) · 5.56 KB

README-zh.md

File metadata and controls

161 lines (116 loc) · 5.56 KB

direct-mail

Codacy Badge Build Status NPM Download NPM Version NPM License PRs Welcome Automated Release Notes by gren

阿里云邮件推送 (DirectMail) Node.js SDK(兼容浏览器端)

Table of Contents

Feature

  • 兼容 Node.js/浏览器端
  • Promise 风格
  • 支持以下 API
    • SingleSendMail 单一发信接口,支持发送触发和其他单个邮件
    • BatchSendMail 批量发信接口,支持通过调用模板的方式发送批量邮件

⬆ Back to Top

Install

yarn add @femessage/direct-mail

⬆ Back to Top

Example

发送单个邮件

const directMail = require('@femessage/direct-mail')

const singleConfig = {
  AccountName: 'yourmail@mail.com',
  FromAlias: '化名',
  ToAddress: 'toaddress@mail.com',
  Subject: '标题',
  HtmlBody: '<html>内容</html>',
  AccessKeyId: process.env.ACCESS_KEY_ID,
  AccessKeySecret: process.env.ACCESS_KEY_SECRET
}

directMail
  .SingleSendMail(singleConfig)
  .then(resp => {})
  .catch(err => {})

批量发送邮件

const directMail = require('@femessage/direct-mail')

const batchConfig = {
  AccountName: 'yourmail@mail.com',
  ReceiversName: 'defaultReceivers',
  TemplateName: 'offer',
  AccessKeyId: process.env.ACCESS_KEY_ID,
  AccessKeySecret: process.env.ACCESS_KEY_SECRET
}

directMail
  .BatchSendMail(batchConfig)
  .then(resp => {})
  .catch(err => {})

dotenv

AccessKeyId、AccessKeySecret 的设置也可以使用dotenv

#.env
ACCESS_KEY_ID=
ACCESS_KEY_SECRET=
// 加载环境变量
require('dotenv').config()

则可以在调用时,不用传 AccessKeyId、AccessKeySecret

const config = {
  AccountName: 'yourmail@mail.com',
  FromAlias: '化名',
  ToAddress: 'toaddress@mail.com',
  Subject: '标题',
  HtmlBody: '<html>内容</html>'
}

directMail
  .SingleSendMail(config)
  .then(resp => {})
  .catch(err => {})

⬆ Back to Top

Attention

  • HtmlBodyTextBody 不能出现英文输入法的括号 (),否则会请求 400,出现报错SignatureDoesNotMatch
  • 当需要超链接时请直接以文本形式写下链接,不需要使用“添加链接”工具

总之,邮件内容最好不要出现英文输入法的特殊字符。

⬆ Back to Top

Reference

⬆ Back to Top

Contributors

Thanks goes to these wonderful people (emoji key):

levy
levy

💻 ⚠️ 📖
donhac
donhac

💻 📖 🚇
ColMugX
ColMugX

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

⬆ Back to Top

License

MIT

⬆ Back to Top

Inspiration

thanks to Mttylzq