Instantiation
Composing a message
Use theMail helper to compose messages. It handles formatting and automatically base64-encodes HTML content before sending.
mail.get() to get the formatted dict ready for the API.
Attachments
optional_headers dict:
Send a message
Check delivery status
deliveryStatus values: delivered, opened, failed, pending.
The Response object
Bothsend and get return a Response object:
| Property | Description |
|---|---|
.status_code | HTTP status code |
.headers | Response headers dict |
.text | Raw response body as a string |
.to_dict | JSON-parsed response body, or None if not JSON |
Error handling
Both methods raiserequests.exceptions.HTTPError on non-2xx responses. Wrap calls in a try/except block:
handle_error helper prints the error response body before re-raising: