Why Use a Custom Client?
A custom HTTP client gives you control over:- Timeouts: Configure request and connection timeouts
- Connection Pooling: Optimize performance for high-volume sending
- Retries: Implement custom retry logic
- Proxies: Route requests through a proxy server
- TLS Configuration: Custom certificate validation
- Middleware: Add request/response interceptors
Basic Custom Client
Create a Resend client with custom timeout settings:Advanced Connection Pooling
Optimize for high-volume email sending with connection pooling:Connection pooling is especially important when sending many emails in parallel. It reduces the overhead of establishing new connections for each request.
Custom Retry Logic
Implement automatic retries with exponential backoff:Proxy Configuration
Route requests through a proxy server:Request/Response Logging
Log all HTTP requests and responses for debugging:Custom TLS Configuration
Configure custom TLS settings for certificate validation:Complete Example
Here’s a production-ready example from examples/send_email_custom_client.go:examples/send_email_custom_client.go
Best Practices
Set appropriate timeouts
Set appropriate timeouts
Always configure timeouts to prevent requests from hanging indefinitely:
Reuse HTTP clients
Reuse HTTP clients
Create a single HTTP client and reuse it across requests. Creating new clients for each request wastes resources:
Use idempotency with retries
Use idempotency with retries
When implementing retry logic, always use idempotency keys to prevent duplicate emails:
Monitor connection pool usage
Monitor connection pool usage
For high-volume applications, monitor and tune connection pool settings:
Next Steps
Error Handling
Handle rate limits and implement retry strategies
Basic Usage
Learn the fundamentals of sending emails
Templates
Use email templates with dynamic variables
Batch Emails
Send multiple emails efficiently