Skip to content

YeungKC/AliMail-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AliMail-SDK

Use AliYun DirectMail service with JavaScript

Codacy Badge codecov Build Status NPM version NPM download Known Vulnerabilities dependencies Status devDependencies Status

install

yarn add alimail-sdk

Example

const AliMailSDK = require('alimail-sdk');

!(async () => {
  const mailer = new AliMailSDK({
    AccessKeyId: 'AccessKeyId',
    AccessKeySecret: 'AccessKeySecret',
    Version: '2015-11-23', // RegionID 是 cn-hangzhou version 是 2015-11-23,其他一律 2017-06-22
    SignatureVersion: '1.0', // 默认并仅支持 1.0
    SignatureMethod: 'HMAC-SHA1', // 默认并仅支持 HMAC-SHA1
    RegionId: 'cn-hangzhou', // 可选
    Format: 'json' // 可选
  })

  const singleRes = await mailer.send(
    {
      Action: 'single',
      AccountName: '[email protected]',
      ReplyToAddress: false, // 默认 false
      AddressType: 0, // 默认 0
      ToAddress: '[email protected]',
      FromAlias: 'alias', // 可选
      Subject: 'subject', // 可选
      TagName: 'test', // 可选
      HtmlBody: '<html>HtmlBody</html>', // 可选
      TextBody: 'TextBody', // 可选
      ClickTrace: '0' // 默认 0
      // Timestamp: new Date().toISOString(), // 默认 new Date().toISOString()
      // SignatureNonce: uuid() // 默认 UUID
    },
    {} // 传入 axios config 设置代理等
  )
  console.log(singleRes) // axios respone

  const batchRes = await mailer.send(
    {
      Action: 'batch',
      AccountName: '[email protected]',
      AddressType: 0, // 默认 0
      TemplateName: 'test',
      ReceiversName: 'listname',
      ClickTrace: '0' // 默认 0
      // Timestamp: new Date().toISOString(), // 默认 new Date().toISOString()
      // SignatureNonce: uuid() // 默认 UUID
    },
    {} // 传入 axios config 设置代理等
  )
  console.log(batchRes) // axios respone
})()

About

Use AliYun DirectMail service with JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published