Client Installation
The VaultSandbox.Client SDK provides a developer-friendly interface for integrating email testing into your .NET applications and test suites.
Requirements
Section titled “Requirements”- .NET: 9.0 or higher
- Platform: Server-side .NET only (not supported in Blazor WebAssembly)
- VaultSandbox Gateway: Running instance with API access
Installation
Section titled “Installation”.NET CLI
Section titled “.NET CLI”dotnet add package VaultSandbox.ClientPackage Manager Console
Section titled “Package Manager Console”Install-Package VaultSandbox.ClientPackageReference
Section titled “PackageReference”<PackageReference Include="VaultSandbox.Client" Version="0.6.0" />
Quick Start
Section titled “Quick Start”Basic Usage
Section titled “Basic Usage”using VaultSandbox.Client;
var client = VaultSandboxClientBuilder.Create() .WithBaseUrl("https://mail.example.com") .WithApiKey("your-api-key") .Build();
var inbox = await client.CreateInboxAsync();Console.WriteLine($"Send email to: {inbox.EmailAddress}");
var email = await inbox.WaitForEmailAsync(new WaitForEmailOptions{ Timeout = TimeSpan.FromSeconds(30)});Console.WriteLine($"Received: {email.Subject}");
await client.DeleteInboxAsync(inbox.EmailAddress);await client.DisposeAsync();Verifying Installation
Section titled “Verifying Installation”Create a test file TestVaultSandbox.cs:
using VaultSandbox.Client;
var client = VaultSandboxClientBuilder.Create() .WithBaseUrl(Environment.GetEnvironmentVariable("VAULTSANDBOX_URL")!) .WithApiKey(Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!) .Build();
try{ var serverInfo = await client.GetServerInfoAsync(); Console.WriteLine("Connected to VaultSandbox"); Console.WriteLine($"Allowed domains: {string.Join(", ", serverInfo.AllowedDomains)}");
var inbox = await client.CreateInboxAsync(); Console.WriteLine($"Created inbox: {inbox.EmailAddress}");
await client.DeleteInboxAsync(inbox.EmailAddress); Console.WriteLine("Cleanup successful");
Console.WriteLine("\nInstallation verified!");}catch (Exception ex){ Console.WriteLine($"Error: {ex.Message}");}finally{ await client.DisposeAsync();}Run it:
export VAULTSANDBOX_URL=https://mail.example.comexport VAULTSANDBOX_API_KEY=your-api-keydotnet runDependency Injection Setup
Section titled “Dependency Injection Setup”ASP.NET Core Integration
Section titled “ASP.NET Core Integration”The SDK provides IServiceCollection extension methods for seamless dependency injection.
Via Configuration Section
Section titled “Via Configuration Section”builder.Services.AddVaultSandboxClient(builder.Configuration);{ "VaultSandbox": { "BaseUrl": "https://gateway.example.com", "ApiKey": "your-api-key" }}Via Configuration Action
Section titled “Via Configuration Action”builder.Services.AddVaultSandboxClient(options =>{ options.BaseUrl = "https://gateway.example.com"; options.ApiKey = Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!;});Via Builder Delegate
Section titled “Via Builder Delegate”builder.Services.AddVaultSandboxClient((clientBuilder, sp) =>{ var config = sp.GetRequiredService<IConfiguration>(); clientBuilder .WithBaseUrl(config["VaultSandbox:BaseUrl"]!) .WithApiKey(config["VaultSandbox:ApiKey"]!) .WithLogging(sp.GetRequiredService<ILoggerFactory>());});Using the Injected Client
Section titled “Using the Injected Client”public class EmailTestService{ private readonly IVaultSandboxClient _client;
public EmailTestService(IVaultSandboxClient client) { _client = client; }
public async Task<string> CreateTestInboxAsync() { var inbox = await _client.CreateInboxAsync(); return inbox.EmailAddress; }}Next Steps
Section titled “Next Steps”- Configuration - Configure the client for your environment
- Core Concepts - Understand inboxes, emails, and authentication
- Guides - Learn common usage patterns
- Testing Patterns - Integrate with your test suite