Sending examples

Send transactional email with Python

Send transactional email from Python with the Sendtern SDK. Test in Email Playground and track live delivery by email ID.

Prerequisites

  • A Sendtern API key stored as SENDTERN_API_KEY
  • Python 3.9 or newer
  1. 1

    Install the SDK

    Run this command in your project.

    1python -m pip install https://github.com/Sendtern/sendtern-sdks/releases/download/v0.3.0/sendtern-0.3.0-py3-none-any.whl
    
  2. 2

    Send an email

    Create send.py and run it with python send.py.

    1import os
    2from sendtern import Sendtern
    3
    4client = Sendtern(os.environ["SENDTERN_API_KEY"])
    5result = client.emails.send({
    6  "from": "Acme <hello@mail.example.com>",
    7  "to": "you@example.com",
    8  "subject": "Welcome to Acme",
    9  "text": "Thanks for signing up."
    10})
    11print(result["id"])
    
  3. 3

    Check the response

    A successful request returns 200 OK with the email id. Use it to look the email up later.

    1{
    2  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
    3}
    

Test without sending

Save this as preview.py and run python preview.py. Open Email Playground to inspect the message and its headers before setting up a sending domain.

1import os
2from sendtern import Sendtern
3
4client = Sendtern(os.environ["SENDTERN_API_KEY"])
5result = client.emails.capture({
6  "from": "sandbox@sendtern.test",
7  "to": "recipient@example.com",
8  "subject": "Welcome email preview",
9  "html": "<p>Thanks for signing up.</p>"
10})
11print(result["id"])

For live email, use the returned ID to check delivery events. See the transactional email plans for monthly sending limits.

Replace the example sender with an address on your verified domain.

Questions sent for AI answers are processed by DeepSeek. Leave out credentials and personal data.