Skip to content

Client Configuration

This page covers all configuration options for the VaultSandbox .NET client.

using VaultSandbox.Client;
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://mail.example.com")
.WithApiKey("your-api-key")
.Build();
PropertyTypeRequiredDefaultDescription
BaseUrlstringYes-Gateway server URL
ApiKeystringYes-API key for authentication
HttpTimeoutMsintNo30000HTTP request timeout (ms)
WaitTimeoutMsintNo30000Default wait timeout (ms)
PollIntervalMsintNo2000Polling interval (ms)
MaxRetriesintNo3Maximum retry attempts
RetryDelayMsintNo1000Initial retry delay (ms)
SseReconnectIntervalMsintNo5000SSE reconnect interval (ms)
SseMaxReconnectAttemptsintNo10Maximum SSE reconnect attempts
DefaultDeliveryStrategyDeliveryStrategyNoAutoDelivery strategy
DefaultInboxTtlSecondsintNo3600Default inbox TTL (seconds)

Type: string

Description: Base URL of your VaultSandbox Gateway

Examples:

.WithBaseUrl("https://mail.example.com")
.WithBaseUrl("http://localhost:3000") // Local development

Requirements:

  • Must include protocol (https:// or http://)
  • Should not include trailing slash
  • Must be accessible from your application

Type: string

Description: API key for authentication

Example:

.WithApiKey("vs_1234567890abcdef...")

Best practices:

  • Store in environment variables or secure configuration
  • Never commit to version control
  • Rotate periodically

Builder Method: WithHttpTimeout(TimeSpan)

Default: 30 seconds

Description: Timeout for individual HTTP requests

.WithHttpTimeout(TimeSpan.FromSeconds(60))

Builder Method: WithWaitTimeout(TimeSpan)

Default: 30 seconds

Description: Default timeout for WaitForEmailAsync operations

.WithWaitTimeout(TimeSpan.FromMinutes(2))

Builder Method: WithPollInterval(TimeSpan)

Default: 2 seconds

Description: Polling interval when using polling strategy

.WithPollInterval(TimeSpan.FromSeconds(1))

Considerations:

  • Lower = more responsive, more API calls
  • Higher = fewer API calls, slower detection
  • Subject to rate limiting

Builder Method: WithMaxRetries(int)

Default: 3

Description: Maximum retry attempts for failed HTTP requests

.WithMaxRetries(5)

Builder Method: WithRetryDelay(TimeSpan)

Default: 1 second

Description: Base delay between retry attempts (uses exponential backoff)

.WithRetryDelay(TimeSpan.FromMilliseconds(500))

Builder Method: WithSseReconnectInterval(TimeSpan)

Default: 5 seconds

Description: Initial delay before SSE reconnection attempt

.WithSseReconnectInterval(TimeSpan.FromSeconds(2))

Builder Method: WithSseMaxReconnectAttempts(int)

Default: 10

Description: Maximum SSE reconnection attempts before giving up

.WithSseMaxReconnectAttempts(20)

Builder Methods: UseAutoDelivery(), UseSseDelivery(), UsePollingDelivery()

Default: Auto

Description: Email delivery strategy

.UseAutoDelivery() // Recommended - tries SSE, falls back to polling
.UseSseDelivery() // Force SSE only
.UsePollingDelivery() // Force polling only

Builder Method: WithDefaultInboxTtl(TimeSpan)

Default: 1 hour

Description: Default time-to-live for created inboxes

.WithDefaultInboxTtl(TimeSpan.FromMinutes(30))
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://gateway.example.com")
.WithApiKey("api-key")
.WithHttpTimeout(TimeSpan.FromSeconds(60))
.WithWaitTimeout(TimeSpan.FromMinutes(2))
.WithPollInterval(TimeSpan.FromSeconds(1))
.WithMaxRetries(5)
.WithRetryDelay(TimeSpan.FromSeconds(2))
.WithSseReconnectInterval(TimeSpan.FromSeconds(3))
.WithSseMaxReconnectAttempts(15)
.UseAutoDelivery()
.WithDefaultInboxTtl(TimeSpan.FromMinutes(30))
.Build();
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole().SetMinimumLevel(LogLevel.Debug);
});
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://gateway.example.com")
.WithApiKey("api-key")
.WithLogging(loggerFactory)
.Build();
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://gateway.example.com"),
Timeout = TimeSpan.FromSeconds(60)
};
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://gateway.example.com")
.WithApiKey("api-key")
.WithHttpClient(httpClient, disposeClient: true)
.Build();
Program.cs
builder.Services.AddVaultSandboxClient(builder.Configuration);
appsettings.json
{
"VaultSandbox": {
"BaseUrl": "https://gateway.example.com",
"ApiKey": "your-api-key",
"HttpTimeoutMs": 60000,
"WaitTimeoutMs": 120000,
"PollIntervalMs": 1000,
"MaxRetries": 5,
"DefaultDeliveryStrategy": "Auto",
"DefaultInboxTtlSeconds": 1800
}
}
builder.Services.AddVaultSandboxClient(
builder.Configuration.GetSection("MyCustomSection"));
builder.Services.AddVaultSandboxClient(options =>
{
options.BaseUrl = Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!;
options.ApiKey = Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!;
options.MaxRetries = 5;
options.DefaultDeliveryStrategy = DeliveryStrategy.Auto;
});
builder.Services.AddVaultSandboxClient((clientBuilder, sp) =>
{
var config = sp.GetRequiredService<IConfiguration>();
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
clientBuilder
.WithBaseUrl(config["VaultSandbox:BaseUrl"]!)
.WithApiKey(config["VaultSandbox:ApiKey"]!)
.WithLogging(loggerFactory)
.WithMaxRetries(5)
.UseAutoDelivery();
});

Store configuration in environment variables:

Terminal window
export VAULTSANDBOX_URL=https://mail.example.com
export VAULTSANDBOX_API_KEY=vs_1234567890abcdef...
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!)
.WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!)
.Build();
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!)
.WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!)
.WithMaxRetries(5)
.WithRetryDelay(TimeSpan.FromSeconds(2))
.WithSseReconnectInterval(TimeSpan.FromSeconds(5))
.WithSseMaxReconnectAttempts(10)
.UseAutoDelivery()
.Build();
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!)
.WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!)
.WithPollInterval(TimeSpan.FromSeconds(1))
.WithMaxRetries(3)
.WithRetryDelay(TimeSpan.FromMilliseconds(500))
.UseAutoDelivery()
.Build();
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("http://localhost:3000")
.WithApiKey("dev-api-key")
.WithPollInterval(TimeSpan.FromMilliseconds(500))
.WithMaxRetries(1)
.UsePollingDelivery()
.Build();
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!)
.WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!)
.WithMaxRetries(10)
.WithRetryDelay(TimeSpan.FromSeconds(2))
.WithSseReconnectInterval(TimeSpan.FromSeconds(1))
.WithSseMaxReconnectAttempts(int.MaxValue)
.UseAutoDelivery()
.Build();

Use when: You want optimal performance with automatic fallback

Behavior:

  1. Tries SSE first
  2. Falls back to polling if SSE fails
  3. Automatically reconnects on errors

Pros:

  • Best of both worlds
  • No manual configuration needed
  • Resilient to network issues

Cons:

  • Slightly more complex internally

Use when: You need real-time, low-latency delivery

Behavior:

  • Persistent connection to server
  • Push-based email notification
  • Instant delivery

Pros:

  • Real-time delivery (no polling delay)
  • Efficient (no repeated HTTP requests)
  • Deterministic tests

Cons:

  • Requires persistent connection
  • May be blocked by some proxies/firewalls
  • More complex error handling

Use when: SSE is blocked or unreliable

Behavior:

  • Periodic HTTP requests for new emails
  • Pull-based email retrieval
  • Configurable interval

Pros:

  • Works in all network environments
  • No persistent connection required
  • Simple and predictable

Cons:

  • Delay based on polling interval
  • More HTTP requests
  • Less efficient than SSE

The client implements IAsyncDisposable. Always dispose properly:

await using var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://gateway.example.com")
.WithApiKey("api-key")
.Build();
// Use client...
// Automatically disposed at end of scope

Or explicitly:

var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://gateway.example.com")
.WithApiKey("api-key")
.Build();
try
{
// Use client...
}
finally
{
await client.DisposeAsync();
}

DO:

// Use environment variables or secure configuration
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!)
.WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!)
.Build();

DON’T:

// Never hard-code credentials
var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl("https://mail.example.com")
.WithApiKey("vs_1234567890...") // Never do this
.Build();

DO:

await using var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(url)
.WithApiKey(apiKey)
.Build();
await RunTestsAsync(client);
// Automatically disposed

DON’T:

var client = VaultSandboxClientBuilder.Create()
.WithBaseUrl(url)
.WithApiKey(apiKey)
.Build();
await RunTestsAsync(client);
// Forgot to dispose - resources leak
using VaultSandbox.Client.Exceptions;
try
{
var inbox = await client.CreateInboxAsync();
}
catch (ApiException ex)
{
Console.WriteLine($"API error: {ex.StatusCode} - {ex.Message}");
}
catch (NetworkException ex)
{
Console.WriteLine($"Network error: {ex.Message}");
}
catch (VaultSandboxTimeoutException ex)
{
Console.WriteLine($"Timeout after {ex.Timeout.TotalSeconds}s");
}
catch (VaultSandboxException ex)
{
Console.WriteLine($"VaultSandbox error: {ex.Message}");
}