Skip to main content
This guide covers common patterns for sending transactional emails with Ark, from simple notifications to complex templates.

Basic Email

Send a simple email with HTML and plain text:
from ark import Ark

client = Ark()

email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Your order has shipped!",
    html="<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>",
    text="Order Shipped\n\nYour order #1234 is on its way."
)

print(f"Email sent: {email.data.id}")
Always include both html and text versions. Some email clients only display plain text, and it improves deliverability.

Multiple Recipients

Send to multiple recipients in a single request:
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]", "[email protected]"],
    cc=["[email protected]"],
    bcc=["[email protected]"],
    subject="Team Update",
    html="<p>Here is your weekly update...</p>"
)
Maximum 50 recipients per request. For larger sends, use the batch endpoint or make multiple requests.

Using Tags and Metadata

Add tags and metadata to categorize and track emails:
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Order Confirmation #1234",
    html="<p>Thank you for your order!</p>",
    tags=["orders", "confirmation"],
    metadata={
        "order_id": "1234",
        "customer_id": "cust_abc123",
        "order_total": "99.99"
    }
)
Tags and metadata are included in webhook events, making it easy to correlate emails with your application data.

Scheduling Emails

Schedule an email to send at a specific time:
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Your Weekly Digest",
    html="<p>Here is what happened this week...</p>",
    scheduled_at="2024-01-20T09:00:00Z"  # ISO 8601 format
)
Emails can be scheduled up to 7 days in advance.

Attachments

Send files as attachments:
import base64

with open("invoice.pdf", "rb") as f:
    pdf_content = base64.b64encode(f.read()).decode()

email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Your Invoice #INV-001",
    html="<p>Please find your invoice attached.</p>",
    attachments=[
        {
            "filename": "invoice.pdf",
            "content": pdf_content,
            "content_type": "application/pdf"
        }
    ]
)
Maximum attachment size is 25MB total. Large attachments may impact deliverability.

Custom Headers

Add custom email headers:
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Re: Support Ticket #5678",
    html="<p>Thank you for contacting support...</p>",
    reply_to="[email protected]",
    headers={
        "X-Ticket-ID": "5678",
        "References": "<[email protected]>",
        "In-Reply-To": "<[email protected]>"
    }
)

Controlling Tracking

Disable tracking for sensitive emails:
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Password Reset",
    html="<p>Click here to reset your password...</p>",
    track_opens=False,
    track_clicks=False
)

Error Handling

All SDKs provide typed exceptions for error handling:
import ark

try:
    email = client.emails.send(
        from_="[email protected]",
        to=["[email protected]"],
        subject="Test",
        html="<p>Test</p>"
    )
    print(f"Email accepted: {email.data.id}")
except ark.BadRequestError as e:
    print(f"Invalid request: {e.message}")
except ark.RateLimitError as e:
    print(f"Rate limited - retry later")
except ark.APIError as e:
    print(f"API error: {e.message}")

Best Practices

Some email clients and spam filters prefer or require plain text versions.
Instead of just [email protected], use "Your Company" <[email protected]>.
Longer subjects get truncated on mobile devices.
Send test emails to yourself to verify formatting across different clients.
Set up webhooks to receive bounce notifications and update your recipient list.

Next Steps