一、注册账号并申请API密钥
mamba系统中发生邮件是以店铺为单位,一个店铺对应一个站点
进入店铺创建发件人邮件地址,并配置发件人域
二、订阅邮件事件
支持邮件事件列表
描述 | eventType | 推送body |
---|---|---|
邮件接收成功,送达推送 | delivery | { "eventData": { "reason": null, "msg_from": "msprvs1=19591MTYiPLLl=[email protected]", "rcpt_to": "[email protected]", "error_code": null, "transmission_id": "7263131452386267250", "timestamp": "1692087550" }, "eventType": "delivery" } |
邮件接收失败 | bounce | { "eventData": { "reason": "554 5.7.1 [internal] recipient address was suppressed due to customer policy", "msg_from": "msprvs1=19591MTYiPLLl=[email protected]", "rcpt_to": "[email protected]", "error_code": "554", "transmission_id": "7267352687971264007", "timestamp": "1692087720" }, "eventType": "bounce" } |
用户打开邮件 | initial_open | { "eventData": { "msg_from": "msprvs1=19591MTYiPLLl=[email protected]", "rcpt_to": "[email protected]", "transmission_id": "7263131452386267250", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36", "timestamp": "1692087571" }, "eventType": "initial_open" } |
用户点击某个链接 | click | { "eventData": { "msg_from": "msprvs1=19591MTYiPLLl=[email protected]", "rcpt_to": "[email protected]", "target_link_url": "https://www.mambasms.com/", "transmission_id": "7263131452386267250", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36", "timestamp": "1692087571" }, "eventType": "click" } |
用户点击列表退订 | list_unsubscribe | { "eventData": { "rcpt_to": "[email protected]", "transmission_id": "7267210421474857068" }, "eventType": "list_unsubscribe" } |
创建 webhook 订阅邮件事件。邮件送达、打开、点击等事件会以post方式推送
curl --request POST \
--url https://api.mambasms.com/api/v1/webhooks \
--header 'X-Mamba-Access-Token: 2cf3144e51524c56bce0109cc06fecd1' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"topic": "transmission/callback",
"url": "填写接收地址,地址最大长度不超过500字符"
}
'
三、调用群发接口
- 邮件群发API域名和主域名不相同
- 单次最大发送系人数量为2000
curl --request POST \
--url https://sending.mambasms.com/api/v1/sending \
--header 'X-Mamba-Access-Token: 2cf3144e51524c56bce0109cc06fecd1' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"subject": "sending",
"preheader": "sending description",
"html": "<span> hello sending</span>",
"text": "",
"from": {
"name": "zhaoqt",
"email": "[email protected]"
},
"recipients": [
{
"address": {
"name": "zhaoqt",
"email": "[email protected]"
}
}
]
}
请求体参数
参数 | 类型 | 说明 | 是否必填 |
---|---|---|---|
subject | string | 邮件主题行,utf-8 字符集 | Y |
preheader | string | 邮件主题行备注,utf-8 字符集 | N |
html | string | 邮件的 text/html MIME 部分的 HTML 内容。至少需要 html 或text,utf-8 字符集 | Y |
text | string | 邮件的text/plain MIME 部分的文本内容。至少需要 html 或text,utf-8 字符集 | N |
from | obj | 发件人 | |
from.name | string | 邮件发件人名称 | Y |
from.email | string | 邮件发件人地址,邮件域名必须DKIM签名后使用 | Y |
recipients | array | 收件人列表 单次最大2000个 | |
recipients[0].address.name | string | 收件人名称 | N |
recipients[0].address.email | string | 收件人邮件地址 | Y |
recipients[0].address.substitutionData | obj | 收件人专属变量,例如:{"lastName","tom"} | |
replyTo | string | 设置用户默认的回复邮件地址,如果 replyTo 没有或者为空,则默认的回复邮件地址为 from | N |
headers | obj | 邮件头部信息, 例如:{"header1": "value1", "header2": "value2"} | N |
substitutionData | obj | 批量发送邮件共有变量,例如:{"brand","mambasms"} | N |
如果需要替换html模板变量参考 模板变量
发送成功返回
{
"totalAccepted": 1,
"totalRejected": 0,
"id": "7267210421474857068",
"code": "200",
"succeed": true,
"message": "succeed"
}
totalAccepted
发送成功接收数量totalRejected
发送拒绝接收数量id
发送返回批次 id 与推送事件中transmission_id
相同succeed
成功返回 true
建议每次群发接口返回 succeed = true
, 为批次id和本次发送收件人邮件做本地映射存储。邮件推送事件回调可以根据transmission_id + rcpt_to 找到具体发件人做后续业务处理