Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:
You can find your API keys in your SendPost Dashboard. Make sure to use your Sub-Account API Key for sending emails.

1. Install

pip
pip install sendpost_python_sdk

2. Getting Started

Python
import os
import sendpost_python_sdk
from sendpost_python_sdk.api import EmailApi
from sendpost_python_sdk.models import EmailMessageObject, EmailAddress, Recipient

configuration = sendpost_python_sdk.Configuration(host="https://api.sendpost.io/api/v1")
configuration.api_key['subAccountAuth'] = "your_sub_account_api_key"

with sendpost_python_sdk.ApiClient(configuration) as api_client:
    email_message = EmailMessageObject()
    email_message.var_from = EmailAddress(email="[email protected]")
    email_message.to = [Recipient(email="[email protected]")]
    email_message.subject = "Hello World"
    email_message.html_body = "<strong>it works!</strong>"
    
    try:
        response = EmailApi(api_client).send_email(email_message)[0]
        print(f"Email sent! Message ID: {response.message_id}")
    except sendpost_python_sdk.exceptions.ApiException as e:
        print(f"Error: {e.status} - {e.body}")
Make sure your sender email domain is verified in your SendPost account before sending emails.

3. Next Steps

Explore more examples and use cases: