Temp mail
in C#.
Spin up disposable inboxes and grab OTP codes straight from C#.
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("https://evilmail.pro") };
http.DefaultRequestHeaders.Add(
"X-API-Key", Environment.GetEnvironmentVariable("EVILMAIL_KEY"));
// Create an inbox that self-destructs after 30 minutes.
var res = await http.PostAsJsonAsync("/api/temp-email", new { ttlMinutes = 30 });
res.EnsureSuccessStatusCode();
using var doc = await res.Content.ReadFromJsonAsync<JsonDocument>();
var data = doc!.RootElement.GetProperty("data");
Console.WriteLine(data.GetProperty("email").GetString());Wiring up temp mail in C# takes just a few lines of HttpClient and System.Text.Json — no SMTP server, no mailbox setup, no fake SDKs. EvilMail gives you a real disposable email API you can call from any .NET app: create a throwaway inbox, poll it until the message lands, then regex the verification code out of the body. It's built for the parts of testing that hurt — end-to-end signup flows, OTP and email-verification checks, and CI pipelines that need a fresh mailbox on every run without a human ever opening an email client.
Why use temp mail in C#
Automated signup & E2E tests
Provision a fresh disposable inbox per test run so registration flows never collide on a reused address. Perfect for xUnit, NUnit, or Playwright suites that assert on the welcome or confirmation email.
OTP & email verification checks
Poll the inbox, read the message, and pull the 6-digit code with a single regex. Your test can complete the full verify-your-email step end to end, exactly like a real user would.
CI/CD pipelines
Read the API key from an environment variable and generate temporary emails on demand inside GitHub Actions, Azure Pipelines, or any runner — no shared test mailbox to clean up or rate-limit.
Scraping & throwaway registrations
When a .NET tool needs a one-time address to unlock a resource, create a temp mail inbox that self-destructs after a set TTL and never touches your real domain.
The flow — C# temp mail in 3 calls
Create a disposable inbox
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("https://evilmail.pro") };
http.DefaultRequestHeaders.Add(
"X-API-Key", Environment.GetEnvironmentVariable("EVILMAIL_KEY"));
// Ask for an inbox with a 30-minute time-to-live.
var res = await http.PostAsJsonAsync(
"/api/temp-email", new { ttlMinutes = 30 });
res.EnsureSuccessStatusCode();
using var doc = await res.Content.ReadFromJsonAsync<JsonDocument>();
var data = doc!.RootElement.GetProperty("data");
string email = data.GetProperty("email").GetString()!;
string token = data.GetProperty("sessionToken").GetString()!;
Console.WriteLine($"Inbox: {email}");
Console.WriteLine($"Token: {token}");Poll until the email arrives
// Reuse `http` and `token` from step 1.
// Check the inbox up to 20 times, 3s apart.
int uid = -1;
for (int i = 0; i < 20; i++)
{
var res = await http.GetAsync($"/api/temp-email/{token}");
res.EnsureSuccessStatusCode();
using var doc = await res.Content.ReadFromJsonAsync<JsonDocument>();
var messages = doc!.RootElement
.GetProperty("data").GetProperty("messages");
if (messages.GetArrayLength() > 0)
{
uid = messages[0].GetProperty("uid").GetInt32();
Console.WriteLine($"Got message uid={uid}");
break;
}
Console.WriteLine("No mail yet, retrying...");
await Task.Delay(TimeSpan.FromSeconds(3));
}
if (uid < 0)
throw new TimeoutException("No email arrived in time.");Read the message & extract the code
using System.Text.RegularExpressions;
// Fetch the full message body by its uid (reuse `http`, `uid`, `token`).
var res = await http.GetAsync(
$"/api/message/{uid}?token={token}");
res.EnsureSuccessStatusCode();
using var doc = await res.Content.ReadFromJsonAsync<JsonDocument>();
var data = doc!.RootElement.GetProperty("data");
string text = data.GetProperty("text").GetString() ?? "";
// Pull the first 6-digit code out of the body.
var match = Regex.Match(text, @"\b(\d{6})\b");
if (match.Success)
Console.WriteLine($"OTP: {match.Groups[1].Value}");
else
Console.WriteLine("No 6-digit code found.");C# temp mail — FAQ
Q1How do I get a temp mail address in C#?−
Send a POST request to https://evilmail.pro/api/temp-email with your X-API-Key header and a JSON body like {"ttlMinutes": 30}. The response's data.email is your disposable address and data.sessionToken is the handle you use to read its inbox. With HttpClient and System.Text.Json it's about ten lines — see the hero snippet above.
Q2Can I use this for automated testing?+
Yes — that's the primary use case. Create a fresh inbox at the start of each test, trigger your app's email, then poll GET /api/temp-email/{sessionToken} until a message appears. It drops cleanly into xUnit, NUnit, or Playwright/.NET E2E suites, and because the key comes from an environment variable it runs unattended in CI.
Q3How do I extract the OTP from the email?+
Fetch the message with GET /api/message/{uid}?token={sessionToken}, take data.text (or data.html), and run a regex. For a standard 6-digit one-time code, Regex.Match(text, @"\b(\d{6})\b") returns the code in group 1. Adjust the pattern if your provider uses a different length or a token in a link.
Q4Do I need an API key, and are there rate limits?+
Yes, every request must include the X-API-Key header — read it from an environment variable such as EVILMAIL_KEY and never hard-code it in source. Requests are rate-limited per key, so keep polling to sensible intervals (around 3 seconds, ~20 attempts, as shown) rather than tight loops. Check your EvilMail dashboard for your plan's exact quota.
Q5How long does the inbox live?+
You control it with the ttlMinutes field when you create the inbox — set it to 30 for a half-hour, or shorter for quick one-off verifications. Once the TTL expires the address and its messages are destroyed, so grab and read your message before the window closes.
Temp mail in other languages
One API key. Disposable inboxes at scale.
Create unlimited throwaway addresses, poll them over HTTP, and pull verification codes straight into your tests and CI. Free to start; custom domains and higher limits on paid plans.

