基于国内 SendCloud 平台实现的邮件相关 SDK。欢迎 PR 并求 star
发布于 6 个月前 作者 danielsss 766 次浏览 来自 分享

请不要吝啬您的 Star,您的支持便是对本人最大的鼓励。非常感谢

A wrapped email sdk for SendCloud

Welcome PRs.

Requirements

  • Node.js > v7.0.*

Dependencies

  • axios
  • debug

Installation

npm i --save mail-sc.js

Usage

Example 1: Recommended. See APIs

const {
  createClient, decomposeAddress, addressParser
} = require('mail-sc.js');
const options = {apiKey: 'your key', apiUser: 'your user'};
const sendCloud = createClient(options);

const address = 'tester<[email protected]>';
const decomposed = decomposeAddress(address);

const addr1 = ['[email protected]', '[email protected]'];
const addr2 = '[email protected], [email protected],         [email protected]';

console.log(addressParser(addr1));
// '[email protected];[email protected]'

console.log(addressParser(addr2, ','));
// '[email protected];[email protected];[email protected]'

const message = {
  from: decomposed.address,
  fromName: decomposed.name,
  to: 'test1@test,com',
  subject: 'test subject',
  html: 'test message'
};
const sendMessage = async () => {
  return await sendCloud.delivery.send(message);
}
sendMessage();

Example 2

const {
  SendCloud, decomposeAddress
} = require('mail-sc.js');
const options = {apiKey: 'your key', apiUser: 'your user'};
const sendCloud = new SendCloud(options);

const address = 'tester<[email protected]>';
const decomposed = decomposeAddress(address);

const message = {
  from: decomposed.address,
  fromName: decomposed.name,
  to: 'test1@test,com',
  subject: 'test subject',
  html: 'test message'
};
const sendMessage = async () => {
  return await sendCloud.send(message);
}

sendMessage();

SendCloud Options

  • apiKey - The send cloud apiKey
  • apiUser - The send cloud apiUser
  • host - The hostname of send cloud api [default: api.sendcloud.net]
  • protocol - http|https [default: http]
  • port - [default: 80]
  • retry - [default: 1]
  • proxy - axios proxy [default: null]
  • timeout - axios timeout [default: 1000 * 6]

SendCloud Methods

Deliveries

Email Template

Address List

Aliases

  • all the method’s parameter same to here

Deliveries

  • delivery.send(Object)}
  • delivery.sendTemplate(Object)}
  • delivery.sendCalendar(Object)}
  • delivery.taskInfo(Object)}

Email Template

  • template.batchQuery(Object)}
  • template.query(Object)}
  • template.add(Object)}
  • template.delete(Object)}
  • template.update(Object)}

Address List

  • addressList.batchQueryAddress(Object)}
  • addressList.addAddress(Object)}
  • addressList.deleteAddress(Object)}
  • addressList.updateAddress(Object)}
  • addressList.batchQueryMember(Object)}
  • addressList.queryMember(Object)}
  • addressList.addMember(Object)}
  • addressList.updateMember(Object)}
  • addressList.deleteMember(Object)}

Planning implementations

SendCloud APIs

  • [x] Deliveries
  • [x] Email Template
  • [x] Address List
  • [ ] Email Label
  • [ ] Domain
  • [ ] API_USER
  • [ ] User Information
  • [ ] Statistics
  • [ ] Delivery Response
  • [ ] Bounce List Management
  • [ ] Unsubscribe Management
  • [ ] Spam Report Management
  • [ ] Lists of Opens And Clicks Management

Build-in utilities

  • [x] .addressParser(addresses, tag) - Normalizing email address list or email string list
  • [x] .decomposeAddress(address) - Decomposing an email address into fromName & address
3 回复

现在服务都不断细化了

@zy445566 意思是 Planning 中的模块都微服务化了? 官网也没看到有详细说明啊~

@danielsss 不是,以前像邮件和文件存储都直接自己完成,现在很多都依托专业的服务平台了,编程行为变化还是很大的,单纯感叹一下

来自酷炫的 CNodeMD

回到顶部