阿里云邮件推送 (DirectMail) Node.js SDK(兼容浏览器端)
- 兼容 Node.js/浏览器端
- Promise 风格
- 支持以下 API
- SingleSendMail 单一发信接口,支持发送触发和其他单个邮件
- BatchSendMail 批量发信接口,支持通过调用模板的方式发送批量邮件
yarn add @femessage/direct-mail
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 => {})
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 => {})
HtmlBody
或TextBody
不能出现英文输入法的括号 (),否则会请求 400,出现报错SignatureDoesNotMatch
。- 当需要超链接时请直接以文本形式写下链接,不需要使用“添加链接”工具
总之,邮件内容最好不要出现英文输入法的特殊字符。
- 更多参数说明,请看aliyun official docs
- direct-mail 相关使用手册,请看操作指南
Thanks goes to these wonderful people (emoji key):
levy 💻 |
donhac 💻 📖 🚇 |
ColMugX 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
thanks to Mttylzq