通过邮件发送 Smart Report
通过电子邮件投递附带 PDF 报告的 SmartReport。你可以让 Verifik 为单行(rowIndex)或全部行(sendAll: true,最多 50 行)渲染 PDF,也可以直接提供预渲染的 printHtml、pdfBase64 或 pdfFiles 负载。
发送邮件会在 SmartReport 文档上记录 emailDelivery,并在成功时触发 smart_batch_report_sent,投递失败时触发 smart_batch_report_delivery_failed。
端点
POST https://api.verifik.co/v2/smart-reports/{id}/send-email
此端点最高接受 64 MB 的 JSON 负载。使用你自己的每客户 Authorization: Bearer <VERIFIK_JWT>,也可通过 Smart-Agent 代理地址 https://ai.verifik.co/v2/smart-reports/{id}/send-email 访问。共享 x402 执行会被拦截并返回 403 Forbidden。
请求头
| 名称 | 值 | 说明 |
|---|---|---|
Content-Type | application/json | 请求体负载格式(上限 64 MB)。 |
Authorization | Bearer <VERIFIK_JWT> | 客户作用域 JWT(authUser.clientId)。 |
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | SmartReport ObjectId。 |
请求体参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
recipients | string[] | 是 | 有效收件人邮箱地址数组(至少 1 个)。 |
subject | string | 否 | 自定义邮件主题行。 |
language | string | 否 | 邮件文案语言:"en" 或 "es"。默认为 "es"。 |
rowIndex | number | 否 | 未启用 sendAll 时,要渲染并附加的从零开始的行索引。 |
sendAll | boolean | 否 | 为 true 时最多发送 50 行(MAX_SEND_ALL_ROWS);当批次超过 1 行时,每行各自生成一个 PDF 附件。 |
engine | string | 否 | PDF 渲染引擎:"pdfkit" 或 "puppeteer"。 |
printHtml | string | 否 | 预渲染 HTML 字符串(最长 64000000 个字符),将自动转换为 PDF 并作为附件发送。 |
pdfBase64 | string | 否 | 预渲染的 base64 编码 PDF 字符串(最长 64000000 个字符),直接作为附件发送。 |
pdfFiles | object[] | 否 | 最多包含 200 个附件对象的数组({ filename, pdfBase64 }),其中每个 filename(最长 80 个字符)与 pdfBase64(最长 64000000 个字符)均为必填。 |
附件与批量发送规则
sendAll上限:发送批次全部行最多支持50行(MAX_SEND_ALL_ROWS)。超过 50 行会返回409 Conflict(send_all_limit)并失败。当批次超过 1 行时,每一行都会作为独立的 PDF 文件附加。- 预渲染负载:如果你的集成已经自行渲染好定制附件,可直接传入
pdfFiles(最多200项)、pdfBase64或printHtml。损坏的 PDF 数据会返回500(invalid_pdf),解析后附件数为零的请求会返回409 Conflict(no_pdf_attachments)。 - 投递结果响应:如果参数校验和 PDF 准备均成功,但邮件传输失败,该端点仍会返回 HTTP
200 OK,其中包含"success": false、"messageId": null与"error"字段,同时记录emailDelivery并触发smart_batch_report_delivery_failed。
请求示例
- Node.js
- PHP
- Python
- Go
- cURL
import axios from "axios";
const run = async () => {
const id = "6801a2b3c4d5e6f7a8b9c0d1";
const { data } = await axios.post(
`https://api.verifik.co/v2/smart-reports/${id}/send-email`,
{
recipients: ["compliance@example.com"],
subject: "Background Verification Report - Applicant 42",
language: "en",
rowIndex: 0,
engine: "puppeteer",
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.VERIFIK_JWT}`,
},
}
);
console.log(data);
};
run();
<?php
$id = "6801a2b3c4d5e6f7a8b9c0d1";
$ch = curl_init("https://api.verifik.co/v2/smart-reports/" . $id . "/send-email");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . getenv("VERIFIK_JWT"),
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"recipients" => ["compliance@example.com"],
"subject" => "Background Verification Report - Applicant 42",
"language" => "en",
"rowIndex" => 0,
"engine" => "puppeteer",
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
import os
import requests
report_id = "6801a2b3c4d5e6f7a8b9c0d1"
url = f"https://api.verifik.co/v2/smart-reports/{report_id}/send-email"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('VERIFIK_JWT')}",
}
payload = {
"recipients": ["compliance@example.com"],
"subject": "Background Verification Report - Applicant 42",
"language": "en",
"rowIndex": 0,
"engine": "puppeteer",
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
id := "6801a2b3c4d5e6f7a8b9c0d1"
body, _ := json.Marshal(map[string]interface{}{
"recipients": []string{"compliance@example.com"},
"subject": "Background Verification Report - Applicant 42",
"language": "en",
"rowIndex": 0,
"engine": "puppeteer",
})
req, _ := http.NewRequest("POST", "https://api.verifik.co/v2/smart-reports/"+id+"/send-email", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("VERIFIK_JWT"))
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var out map[string]interface{}
json.NewDecoder(resp.Body).Decode(&out)
fmt.Println(out)
}
curl -X POST "https://api.verifik.co/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/send-email" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VERIFIK_JWT" \
-d '{
"recipients": ["compliance@example.com"],
"subject": "Background Verification Report - Applicant 42",
"language": "en",
"rowIndex": 0,
"engine": "puppeteer"
}'
响应示例
- 200 OK(已发送)
- 200 OK(投递失败)
- 401
- 403
- 404
- 409
- 422
- 500
{
"success": true,
"message": "Email sent successfully",
"recipients": ["compliance@example.com"],
"messageId": "<message-id@example.com>"
}
{
"success": false,
"message": "Failed to send email",
"recipients": ["compliance@example.com"],
"messageId": null,
"error": "SMTP transport rejected recipient"
}
{
"message": "Unauthorized",
"code": "Unauthorized"
}
{
"message": "Shared x402 execution is forbidden on this endpoint",
"code": "Forbidden"
}
{
"message": "not_found",
"code": "NotFound"
}
{
"message": "send_all_limit",
"code": "send_all_limit"
}
{
"message": "UnprocessableEntity",
"code": "UnprocessableEntity"
}
{
"message": "invalid_pdf",
"code": "invalid_pdf"
}
错误码说明
| 状态码 | 错误码 / 类型 | 原因 |
|---|---|---|
401 | Unauthorized | JWT 缺失或无效。 |
403 | Forbidden | 尝试使用共享 x402 执行;请改用你自己的每客户 JWT。 |
404 | not_found | 报告 ID 不存在或属于其他客户。 |
404 | template_not_found | 无法找到关联的模板。 |
409 | MissingParameter | Joi 校验失败(例如缺少或无效的 recipients)。 |
409 | send_all_limit | 对超过 50 行的批次请求了 sendAll: true(MAX_SEND_ALL_ROWS)。 |
409 | no_pdf_attachments | 无法为本次请求解析或渲染出任何 PDF 附件。 |
409 | row_not_found | 所请求的 rowIndex 在批次中不存在。 |
422 | UnprocessableEntity | Mongoose 校验错误。 |
500 | invalid_pdf | 所提供的 pdfBase64 或 pdfFiles 负载不是有效的 PDF。 |
Webhooks 与 MCP 集成
- Webhooks:投递成功时自动触发
smart_batch_report_sent,投递失败时触发smart_batch_report_delivery_failed,并在SmartReport上记录emailDelivery。详见 SmartReports Webhooks。 - MCP 等效工具:AI 智能体可通过
smart_report_send_emailMCP 工具发送报告邮件。详见 MCP 与 AI 智能体。
注意事项
- 请务必检查
200 OK响应体中的success字段,因为邮件传输错误会返回success: false、messageId: null与error,而不是非 200 状态码。 - 如果希望在单次调用中同时执行核验步骤、生成 PDF 并发送邮件,请使用 运行 Smart Report。