Skip to content

Client Installation

The VaultSandbox.Client SDK provides a developer-friendly interface for integrating email testing into your .NET applications and test suites.

  • .NET: 9.0 or higher
  • Platform: Server-side .NET only (not supported in Blazor WebAssembly)
  • VaultSandbox Gateway: Running instance with API access
Terminal window
dotnet add package VaultSandbox.Client
Terminal window
Install-Package VaultSandbox.Client
<PackageReference Include="VaultSandbox.Client" Version="0.6.0" />
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();

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:

Terminal window
export VAULTSANDBOX_URL=https://mail.example.com
export VAULTSANDBOX_API_KEY=your-api-key
dotnet run

The SDK provides IServiceCollection extension methods for seamless dependency injection.

Program.cs
builder.Services.AddVaultSandboxClient(builder.Configuration);
appsettings.json
{
"VaultSandbox": {
"BaseUrl": "https://gateway.example.com",
"ApiKey": "your-api-key"
}
}
builder.Services.AddVaultSandboxClient(options =>
{
options.BaseUrl = "https://gateway.example.com";
options.ApiKey = Environment.GetEnvironmentVariable("VAULTSANDBOX_API_KEY")!;
});
builder.Services.AddVaultSandboxClient((clientBuilder, sp) =>
{
var config = sp.GetRequiredService<IConfiguration>();
clientBuilder
.WithBaseUrl(config["VaultSandbox:BaseUrl"]!)
.WithApiKey(config["VaultSandbox:ApiKey"]!)
.WithLogging(sp.GetRequiredService<ILoggerFactory>());
});
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;
}
}