批量发送邮件

GET
POST
https://api.itniotech.com/email/batchSendEmail
可以通过此API批量发送TEXT或者HTML邮件,适用于营销类、通知类邮件。批量发送之前,需先创建收件人列表、发信地址、邮件模板。
请求参数
appId
String
必填
应用id(邮件-邮件应用)
fromEmailAddress
String
必填
在ITNIO TECH平台配置的发信地址,例如:noreply@mail.itniotech.com
receiverId
String
在ITNIO TECH平台配置的收件人列表ID,如果有变量,发送的时候会取模板中的变量值
subject
String
发送邮件,需要设置一个主题,可以是一次性的发送主题或者可重复使用的模板主题。至少需要设置一种主题,字数限制(1~100个字符)
templateID
String
必填
在ITNIO TECH平台配置的审核通过的模板ID
url
String
必填
回调地址
language
String
语言枚举,如:en、zh,不传使用默认模板;其他语言参见模板语言表
adFlag
Int
是否添加广告标识 0:不添加, 1:添加到subject前面,2:添加到subject后面
triggerID
Int
触发器ID
请求示例
//GET请求示例发送 “hello world”主题邮件
Request URL:
    https://api.itniotech.com/email/batchSendEmail?appId=fKFtblIy&fromEmailAddress=test@mailpush.itnio.cn&receiverId=1000&subject=helloWorld&templateID=1&url=https://IP:port/task/email/notice&adFlag=1&triggerID=10&language=en
Request Method:
    GET
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9


//POST请求示例发送 “hello world” 内容:
Request URL:
    https://api.itniotech.com/email/batchSendEmail
Request Method:
    POST
Request Headers:
    Content-Type: application/json;charset=UTF-8
    Sign: 05d7a50893e22a5c4bb3216ae3396c7c
    Timestamp: 1630468800
    Api-Key: bDqJFiq9
Request Body:
{
    "appId":"fKFtblIy",
    "romEmailAddress":"test@mailpush.itnio.cn",
    "receiverId":"1000",
    "subject":"hello world",
    "templateID":"1",
    "url":"https://IP:port/task/email/notice",
    "adFlag":0,
    "triggerID":10,
    "language":"en"
}
响应参数
参数 说明 类型
status 状态码,0成功,其他失败参见邮件状态码说明 String
reason 失败原因说明 String
taskId 任务ID String

注:提交发送邮件成功后,系统会给一个任务ID,根据回调地址程序会进行发送信息的推送。

批量发送回调API(bathWebhook):
参数 说明 类型
taskId 任务ID String
emailId 提交邮件对应平台emailId String
toAddress 提交收件人地址 String
emailState 提交状态:失败、成功 String
remark 成功/失败描述 String

说明:大批量发送邮件时,单个邮件提交完成后,ITNIO TECH将以消息通知的方式,传递到回调地址。

响应状态码
status 状态说明
0 成功
-1 身份验证错误
-2 重复请求
-4 用户锁定
-6 时间戳过期
-8 限制IP访问
-9 发送地址不能为空
-10 模板ID无效或者不可用
-11 模板不存在
-12 模板状态不正确
-13 收件人地址不能为空
-16 收件人列表不存在
-17 邮件主题不能为空且字符限制一百以内
-19 账户余额不足,请及时充值
-20 资费包额度不足,请及时购买
-21 没有可用套餐,暂不能发送邮件
-22 接口异常
-23 端口或者程序异常
-24 您的账号未验证,请验证!
-25 模板ID只能为整数
-26 没有分配客户经理。请与客服人员联系
-27 无法识别logo参数
-29 回调url不能为空
-30 TriggerID错误

意见反馈

文档内容是否对您有帮助?

LANGUAGE

Java

PHP

Curl

Python

REQUEST

import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;

import java.time.LocalDateTime;
import java.time.ZoneId;

public void batchSendEmail(){
    final String baseUrl = "https://api.itniotech.com/email";
    final String apiKey = "your api key";
    final String apiPwd = "your api secret";
    final String appId = "{{appId}}";

    final String fromEmailAddress = "{{fromEmailAddress}}"; // The Mail address configured in the ITNIO
    final String receiverId = "{{receiverId}}"; //Recipient List ID
    final String subject = "{{subject}}"; //Send Message Subject
    final String templateID = "{{templateID}}"; //Send Template ID
    final String url = "{{url}}"; //Callback URL
    final int adFlag = "{{adFlag}}"; //Whether to add the advertising logo
    final String language = "{{language}}"; //language
    final int triggerID = "{{triggerID}}"; //Automation trigger id
    final String requestUrl = baseUrl.concat("/batchSendEmail");

    HttpRequest request = HttpRequest.post(requestUrl);

    // currentTime
    final String datetime = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond());
    // generate md5 key
    final String sign = SecureUtil.md5(apiKey.concat(apiPwd).concat(datetime));
    request.header(Header.CONNECTION, "Keep-Alive")
            .header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")
            .header("Sign", sign)  //Signature with encryption
            .header("Timestamp", datetime) //Current system time stamp (second)
            .header("Api-Key", apiKey); //API KEY(Home-Developer options)

    final String params = JSONUtil.createObj()
            .set("appId", appId)
            .set("fromEmailAddress", fromEmailAddress)
            .set("receiverId", receiverId)
            .set("subject", subject)
            .set("templateID", templateID)
            .set("url", url)
            .set("adFlag", adFlag)
            .set("triggerID",triggerID)
            .set("language", language)
            .set("triggerID",triggerID)
            .toString();

    HttpResponse response = request.body(params).execute();
    if (response.isOk()) {
        String result = response.body();
        System.out.println(result);
    }
} 

REQUEST

header('content-type:text/html;charset=utf8');

$apiKey = "your api key";
$apiSecret = "your api secret";
$appId = "your appid";
$timeStamp = time();
$sign = md5($apiKey . $apiSecret . $timeStamp);

$fromEmailAddress = urlencode("{{fromEmailAddress}}");
$receiverId = "{{receiverId}}";
$templateID = "{{templateID}}";
$subject = urlencode("{{subject}}");
$backUrl = urlencode("{{url}}");
$language = "{{language}}";
$adFlag = "{{adFlag}}";
$triggerID = "{{triggerID}}";

$url = "https://api.itniotech.com/email/batchSendEmail?appId=$appId&fromEmailAddress=$fromEmailAddress&receiverId=$receiverId&subject=$subject&templateID=$templateID&url=$backUrl&language=$language&adFlag=$adFlag";

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => array(
        "Content-Type: application/json;charset=UTF-8",
        "Sign: $sign",
        "Timestamp: $timeStamp",
        "Api-Key: $apiKey"
    ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;

REQUEST

curl --location --request GET 'https://api.itniotech.com/email/batchSendEmail'
--header 'Content-Type: application/json;charset=UTF-8'
--header 'Sign: {sign}'
--header 'Timestamp: {datetime}'
--header 'Api-Key: {apiKey}'
--data-raw '{"appId": "{{appId}}","fromEmailAddress": "{{fromEmailAddress}}","receiverId": "{{receiverId}}","subject": "{{subject}}","templateID": "{{templateID}}","url":"{{url}}","language":"{{language}}","adFlag":{{adFlag}},"triggerID":"{{triggerID}}"}'

REQUEST

import hashlib
import time
import requests
import json

base_url = "https://api.itniotech.com/email/batchSendEmail"
api_key = "your api key"
api_pwd = "your api secret"
app_id = "your appid"

timestamp = int(time.time())
s = "%s%s%s" % (api_key, api_pwd, str(timestamp))
sign = hashlib.md5(s.encode(encoding='UTF-8')).hexdigest()

headers = {
    'Content-Type': 'application/json;charset=utf-8',
    'Sign': sign,
    'Timestamp': str(timestamp),
    'Api-Key': api_key
}

fromEmailAddress = "{{fromEmailAddress}}"
receiverId = "{{receiverId}}"
subject = "{{subject}}"
templateID = "{{templateID}}"
emailUrl = "{{url}}"
adFlag = "{{adFlag}}"
language = "{{language}}"

params = {"appId": app_id, "fromEmailAddress": fromEmailAddress, "receiverId": receiverId, "subject": subject,
          "templateID": templateID, "url": emailUrl, "language": language, "adFlag": adFlag}
print(params)

rsp = requests.get(base_url, params, headers=headers)

if rsp.status_code == 200:
    data = json.loads(rsp.text)
    print(data)

RESPONSEEXAMPLE

{
    "status": "0",
    "reason": null,
    "taskId": "630361b19ef86e51f4de07f1"
}