Skip to main content
The Resend Go SDK allows you to provide a custom HTTP client for advanced configurations like custom timeouts, connection pooling, and transport settings.

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:
Be careful with retry logic for email sending. Use idempotency keys to prevent duplicate emails on retry.

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

Always configure timeouts to prevent requests from hanging indefinitely:
Create a single HTTP client and reuse it across requests. Creating new clients for each request wastes resources:
When implementing retry logic, always use idempotency keys to prevent duplicate emails:
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