邮件
事务性邮件,支持模板、域名验证与投递追踪。
概览
基础路径:
/v1/emailPython 命名空间:
infra.emailtext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.email方法
email.send
POST /v1/email/send
发送事务性邮件;支持模板、附件与 BYOK 供应商。
Python
python
infra.email.send(to, subject, body, *, from_=None, html=False, cc=None, bcc=None, template_id=None, template_vars=None, attachments=None, vendor=None, idempotency_key=None)TypeScript
typescript
client.email.send(opts: EmailSendOptions): Promise<EmailRecord>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
to | string | string[] | 必填 | 收件地址或地址列表。 |
subject | string | 必填 | 邮件主题。 |
text | string | 可选 | 纯文本正文。 |
html | string | 可选 | HTML 正文。 |
from | string | 可选 | 发件地址(需已验证域名)。 |
cc | string[] | 可选 | 抄送地址。 |
bcc | string[] | 可选 | 密送地址。 |
template_id | string | 可选 | 用于渲染的模板 id(替代正文)。 |
template_vars | Record<string, unknown> | 可选 | 传入模板的变量。 |
attachments | Array<{ filename, content, mime? }> | 可选 | 要附加的文件。 |
vendor | string | 可选 | 固定使用某个供应商,而非自动路由。 |
idempotency_key | string | 可选 | 可选去重 key;相同重试将返回同一结果。 |
返回
EmailRecord { email_id, state, to, subject, vendor, created_at }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
sent = infra.email.send(
to="alice@example.com",
subject="Welcome to Infrai",
body="<h1>Welcome!</h1><p>Your account is ready.</p>",
html=True,
)
print("message_id:", sent.get("message_id") or sent.get("id"))email.get
GET /v1/email/{id}
按 id 获取单条邮件记录。
Python
python
infra.email.get(id=email_id)TypeScript
typescript
client.email.get(emailId: string): Promise<EmailRecord>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | 邮件记录 id。 |
返回
EmailRecord示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
rec = infra.email.get(id="msg_...")
print("state:", rec.get("state"), "| to:", rec.get("to"))email.list
GET /v1/email
列出邮件记录,支持状态与分页过滤。
Python
python
infra.email.list(project_id=None, state=None, limit=None, cursor=None)TypeScript
typescript
client.email.list(query): Promise<{ items, next_cursor? }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
state | string | 可选 | 按记录状态过滤。 |
limit | number | 可选 | 返回的最大条数。 |
cursor | string | 可选 | 分页游标。 |
返回
{ items: EmailRecord[], next_cursor? }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
page = infra.email.list(state="delivered", limit=20)
for e in page.get("items", []):
print(e.get("email_id"), e.get("state"))email.suppress
POST /v1/email/suppress
将某地址加入抑制名单。
Python
python
infra.email.suppress(...)TypeScript
typescript
// see ROUTES["email.suppress"]返回
SuppressionRecord示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
s = infra.email.suppress(email="bounce@example.com", reason="hard_bounce")
print("suppressed:", s.get("email") or s.get("ok"))email.domain.verify
POST /v1/email/domains/verify
验证发件域名并返回所需 DNS 记录。
Python
python
infra.email.domain.verify(domain=...)TypeScript
typescript
client.email.verifyDomain(domain: string): Promise<{ verified, records }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
domain | string | 必填 | 要验证的域名。 |
返回
{ verified, records: Array<{ type, name, value }> }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
res = infra.email.domain.verify(domain="mail.example.com")
print("verified:", res.get("verified"))
for rec in res.get("records", []):
print(" ", rec.get("type"), rec.get("name"), "->", rec.get("value"))