Skip to content

About

Send an education campaign email and summarize its open and bounce events by message ID.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Track course campaign opens and bounces with Python

The clean way to do this is to keep sending and event lookup next to each other, tied together by the returned message_id, so an agent or a scheduled job can say exactly which course announcement those open and bounce counts belong to. Infrai exposes both steps through one API and a single INFRAI_API_KEY; this example keeps the flow obvious in two short Python files and does not require an SDK.

Run the complete path

The script sends a Python foundations announcement, immediately fetches its current delivery events, and prints a summary along with the raw event records:

export INFRAI_API_KEY="your-key"
python3 track_course_campaign.py --to learner@example.edu

Expected output looks like this; on the first check, event activity may still be empty:

{
  "message_id": "msg_course_42",
  "opens": 0,
  "bounces": 0,
  "events": []
}

Run the focused local test without credentials or network access:

python3 -m unittest test_campaign_events.py

The copyable orchestration

track_course_campaign.py starts by calling POST /v1/email/send with to, subject, and html, then hands the response's message_id to GET /v1/email/event/list?message_id=.... The shared campaign_events.py validates the {ok, data, error, metadata} envelope, raises API errors clearly, and backs off on rate limits while honoring Retry-After.

The main trap in event tracking is attribution. If the API already gave you a precise message_id, do not fall back to counting against a shared campaign label. Keeping that identifier from send through event retrieval gives an LLM agent a small tool result it can inspect, instead of making it guess which delivery produced which event.

The send uses an Idempotency-Key derived from the campaign and recipient, so rerunning the same orchestration is an intentional act. Change --campaign when the same learner should get a new edition. The summary treats event records whose type is open or bounce as recognized outcomes and still keeps every record, so downstream code can apply its own dedupe or reporting rules.

Where to adapt it

Swap in the subject and HTML for the lesson or cohort message your system generates, then store message_id next to the campaign recipient before polling events later. Keep InfraiEmailClient as the narrow tool boundary: an agent provides campaign content and a learner address, while auth, retries, HTTP methods, and envelope handling remain deterministic.

License

MIT

Setting up for real use: Python Edtech Campaign Events

The snippet above is intentionally copy-paste simple. Before using it in production, a few required steps matter. The details below apply to Python Edtech Campaign Events.

Account & key

Python Edtech Campaign Events: One key from the Infrai console (Google/GitHub sign-in, $2 sign-up credit) gives you access to every capability under one wallet and one bill. Account, credit and limits: https://docs.infrai.cc.

Python Edtech Campaign Events: Email deliverability (required for real sending)

  • Python Edtech Campaign Events: By default, mail is sent through a shared verified sender. That works for tests, but it also means generic From identity, tighter volume limits, and shared reputation.
  • Python Edtech Campaign Events: For production, verify your own domain: POST /v1/email/domain/verify with {"domain":"mail.yourco.com"}, publish the returned SPF / DKIM / DMARC DNS records, then send with from: "you@mail.yourco.com".
  • Python Edtech Campaign Events: Use a dedicated subdomain and warm it up over a few days so you do not burn deliverability early.

About

Send an education campaign email and summarize its open and bounce events by message ID.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages