跳到正文

邮件

事务性邮件,支持模板、域名验证与投递追踪。

概览

基础路径: /v1/email
Python 命名空间: infra.email
text
# 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>

参数

名称类型必填说明
tostring | string[]
必填
收件地址或地址列表。
subjectstring
必填
邮件主题。
textstring可选纯文本正文。
htmlstring可选HTML 正文。
fromstring可选发件地址(需已验证域名)。
ccstring[]可选抄送地址。
bccstring[]可选密送地址。
template_idstring可选用于渲染的模板 id(替代正文)。
template_varsRecord<string, unknown>可选传入模板的变量。
attachmentsArray<{ filename, content, mime? }>可选要附加的文件。
vendorstring可选固定使用某个供应商,而非自动路由。
idempotency_keystring可选可选去重 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>

参数

名称类型必填说明
idstring
必填
邮件记录 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? }>

参数

名称类型必填说明
statestring可选按记录状态过滤。
limitnumber可选返回的最大条数。
cursorstring可选分页游标。

返回

{ 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 }>

参数

名称类型必填说明
domainstring
必填
要验证的域名。

返回

{ 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"))