Skip to content

FEMessage/direct-mail

Repository files navigation

direct-mail

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

Alibaba Cloud Email Service (direct mail) Node. js SDK (compatible with browser side)

中文文档

Table of Contents

Feature

  • Compatible with Node.js/browser
  • Promise style
  • Support the following API
    • SingleSendMail, supports sending triggers and other single mail
    • BatchSendMail, supports sending a batch of mails by calling templates

⬆Back to Top

Install

yarn add @femessage/direct-mail

⬆Back to Top

Example

Send A Single 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 => {})

Send A Batch of Mails

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 can also be set via dotenv

#.env
ACCESS_KEY_ID=
ACCESS_KEY_SECRET=
// load the config
require('dotenv').config()

Then AccessKeyId and AccessKeySecret can be omitted.

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

  • HtmlBody Or TextBody cannot contain the brackets () of the English input method, otherwise the signature will not pass.
  • Please only type your link by text when you need hyperlink, DON'T USE "ADD LINK" TOOL.

In short, it is best not to have English input method special characters in the mail content.
⬆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!

License

MIT

⬆ Back to Top

Inspiration

thanks to Mttylzq