This example demonstrates how to use metadata fields when creating drafts and sending messages using the Nylas Python SDK.
- Create drafts with custom metadata fields
- Send messages with custom metadata fields
- Error handling and environment variable configuration
- Clear output and status messages
- A Nylas account with API access
- Python 3.x installed
- Local installation of the Nylas Python SDK (this repository)
- Install the SDK in development mode from the repository root:
cd /path/to/nylas-python
pip install -e .- Set your environment variables:
export NYLAS_API_KEY="your_api_key"
export NYLAS_GRANT_ID="your_grant_id"
export TEST_EMAIL="recipient@example.com" # Optional- Run the example from the repository root:
python examples/metadata_field_demo/metadata_example.pyDemonstrating Metadata Field Usage
=================================
1. Creating draft with metadata...
✓ Created draft with ID: draft-abc123
Request ID: req-xyz789
2. Sending message with metadata...
✓ Sent message with ID: msg-def456
Request ID: req-uvw321
Example completed successfully!
The example includes proper error handling for:
- Missing environment variables
- API authentication errors
- Draft creation failures
- Message sending failures
For more information about the Nylas Python SDK and its features, visit: