Skip to content

Email

Transactional email with templates, domain verification and delivery tracking.

Overview

Base path: /v1/email
Python namespace: 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

Methods

email.send

POST /v1/email/send

Send a transactional email; supports templates, attachments and BYOK vendors.

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>

Parameters

NameTypeRequiredDescription
tostring | string[]
Required
Recipient address or list of addresses.
subjectstring
Required
Subject line.
textstringOptionalPlain-text body.
htmlstringOptionalHTML body.
fromstringOptionalSender address (requires a verified domain).
ccstring[]OptionalCarbon-copy addresses.
bccstring[]OptionalBlind carbon-copy addresses.
template_idstringOptionalTemplate id to render instead of a body.
template_varsRecord<string, unknown>OptionalVariables passed to the template.
attachmentsArray<{ filename, content, mime? }>OptionalFiles to attach.
vendorstringOptionalPin a specific vendor instead of auto-routing.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

EmailRecord { email_id, state, to, subject, vendor, created_at }

Example

一次性前置(每个范例都假定已完成):

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}

Fetch a single email record by id.

Python

python
infra.email.get(id=email_id)

TypeScript

typescript
client.email.get(emailId: string): Promise<EmailRecord>

Parameters

NameTypeRequiredDescription
idstring
Required
The email record id.

Returns

EmailRecord

Example

一次性前置(每个范例都假定已完成):

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

List email records with state and pagination filters.

Python

python
infra.email.list(project_id=None, state=None, limit=None, cursor=None)

TypeScript

typescript
client.email.list(query): Promise<{ items, next_cursor? }>

Parameters

NameTypeRequiredDescription
statestringOptionalFilter by record state.
limitnumberOptionalMaximum items to return.
cursorstringOptionalPagination cursor.

Returns

{ items: EmailRecord[], next_cursor? }

Example

一次性前置(每个范例都假定已完成):

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

Add an address to the suppression list.

Python

python
infra.email.suppress(...)

TypeScript

typescript
// see ROUTES["email.suppress"]

Returns

SuppressionRecord

Example

一次性前置(每个范例都假定已完成):

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

Verify a sending domain and return required DNS records.

Python

python
infra.email.domain.verify(domain=...)

TypeScript

typescript
client.email.verifyDomain(domain: string): Promise<{ verified, records }>

Parameters

NameTypeRequiredDescription
domainstring
Required
The domain to verify.

Returns

{ verified, records: Array<{ type, name, value }> }

Example

一次性前置(每个范例都假定已完成):

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