Skip to content
Mailcycle
Get started
C# and .NET email SDK

Receive email in C#: an email API and library for .NET.

Receive email in C# without a mail server or SmtpClient. The Mailcycle C# email API creates an address, awaits the next message, reads its text, HTML and attachments, and replies in the thread. Every call is async, mail is stored encrypted, and it is opened inside your .NET process.

Install the .NET package
dotnet add package Mailcycle
.NET: receive and read a message
using Mailcycle;

var phrase = Environment.GetEnvironmentVariable("MAILCYCLE_PHRASE")
    ?? throw new InvalidOperationException("MAILCYCLE_PHRASE is not set");
using var mc = await MailcycleClient.SignInAsync(phrase);
var address = await mc.Addresses.CreateAsync(new NewAddress());
Console.WriteLine($"Send an email to {address.EmailAddress}");

var message = await mc.Messages.WaitForAsync(new WaitFor
{
    AddressId = address.Id,
    Timeout = TimeSpan.FromMinutes(5),
});
Console.WriteLine($"{message.Subject} {message.Text}");
  • Mailcycle
  • .NET 8 or later

The .NET SDK is one way into the Mailcycle email API. Full reference at https://docs.mailcycle.email.

Quickstart

Receive and send email in C# and .NET.

Sign in, create an address, wait for a message and answer it. That is the whole loop, and it is the same loop whether the mail is a sign-up code, a customer or a receipt.

  1. 1Install Mailcycle. Create a free account (no card) and set MAILCYCLE_PHRASE to the twelve-word recovery phrase it shows you.
  2. 2Create an address with mc.Addresses.CreateAsync(). It receives mail straight away.
  3. 3Wait for the next message with mc.Messages.WaitForAsync(), or take it from a webhook.
  4. 4Reply with mc.Messages.SendAsync(), threaded under the original.
The full .NET guide
.NET: create an address, wait for mail, reply
using Mailcycle;

var phrase = Environment.GetEnvironmentVariable("MAILCYCLE_PHRASE")
    ?? throw new InvalidOperationException("MAILCYCLE_PHRASE is not set");
using var mc = await MailcycleClient.SignInAsync(phrase);

// A new address that receives mail, sealed to your key.
var address = await mc.Addresses.CreateAsync(new NewAddress
{
    Prefix = "signup",
    Label = "Test run 42",
});
Console.WriteLine(address.EmailAddress); // signup-x7k2@...

// Wait for the verification email, decrypted here.
var message = await mc.Messages.WaitForAsync(new WaitFor
{
    AddressId = address.Id,
    Subject = "verification",
    Timeout = TimeSpan.FromMinutes(5),
});
Console.WriteLine($"{message.Subject} {message.Text}");

// Reply in the same thread.
await mc.Messages.SendAsync(new Outgoing(address.EmailAddress, message.ReplyTo, $"Re: {message.Subject}", "Thanks, confirmed.")
{
    ReplyTo = message,
});
Receive email

Receive email in C#.

Create an address, await the next email that lands on it, then read the sender, subject, text and attachments from a plain C# record. Mail that is already there comes back from AllAsync.

  • WaitForAsync returns the next message, decrypted, within the Timeout you set.
  • mc.Messages.AllAsync(addressId) lists the mail already received.
  • Attachments come back as byte arrays, opened in your .NET process.
.NET: receive email and save its attachments
using Mailcycle;

var phrase = Environment.GetEnvironmentVariable("MAILCYCLE_PHRASE")
    ?? throw new InvalidOperationException("MAILCYCLE_PHRASE is not set");
using var mc = await MailcycleClient.SignInAsync(phrase);

// An address that receives email from now on.
var address = await mc.Addresses.CreateAsync(new NewAddress { Prefix = "orders" });
Console.WriteLine($"Send an email to {address.EmailAddress}");

// Receive the next email, waiting up to five minutes.
var message = await mc.Messages.WaitForAsync(new WaitFor
{
    AddressId = address.Id,
    Timeout = TimeSpan.FromMinutes(5),
});
Console.WriteLine($"{message.FromAddress}: {message.Subject}");
Console.WriteLine(message.Text);

// Save each attachment, opened on this machine.
foreach (var file in message.Attachments)
{
    var bytes = await mc.Messages.AttachmentAsync(message, file.Index);
    await File.WriteAllBytesAsync(Path.GetFileName(file.Filename), bytes);
}
What it does

The whole email API, from .NET.

Everything the Mailcycle console can do is in the package: addresses, inbound mail, sending, webhooks, events, API keys and devices.

Create email addresses from .NET

mc.Addresses.CreateAsync() mints a new address on a shared domain, or on your own domain from Scale, and it receives mail at once. Give it a prefix and a label sealed on your machine.

Receive email and wait for it

mc.Messages.WaitForAsync() listens on the event stream and returns the next matching message, filtered by sender or subject, opened and ready to read. Without a stream it checks every five seconds.

Read and parse incoming email

mc.Messages.AllAsync() and .AttachmentAsync() return the sender, subject, plain text, the original HTML, a safe HTML with remote images and trackers removed, and every attachment as bytes.

Send email and reply in the thread

mc.Messages.SendAsync() sends from an address your account owns, with up to ten files. Pass the message you are answering and the threading headers are filled in.

Inbound email webhooks

Register a URL and every message.received event is POSTed to it, signed with HMAC-SHA256 and retried. WebhookSignature.VerifyNow() checks the signature in one line.

A live event stream

mc.Events.Stream() carries the same events over a WebSocket the moment they happen, and reconnects after a drop. Events carry ids, never content.

Email testing

Test email verification in xUnit, NUnit, MSTest and Playwright for .NET.

Create an address in a test fixture, drive your sign-up page with Playwright, then await WaitForAsync and read the code from message.Text. A timeout throws an ApiException with Code "timeout", and a CancellationToken stops the wait when the test run is cancelled.

  • A real address on a real domain, so the mail goes through the same path your users' does.
  • One call blocks until the message lands, filtered by subject or sender, with a timeout you set.
  • Text, HTML and attachments come back parsed, so pulling out a code or a link is a regular expression.
  • Mail received from the moment you start waiting counts, even if it lands before the stream is up.
Inbound email webhooks

Handle incoming email in ASP.NET Core, Azure Functions and Worker Services.

Rather than polling, let the mail come to you. A webhook POSTs each event to your URL the moment it happens, signed so you can prove it came from Mailcycle, and retried if your server is down.

Events carry ids, never content. Fetch the message by id and it is opened in your code, exactly as it would be otherwise. Webhooks are on Operator and above.

Webhooks in the docs
ASP.NET Core minimal API: verify, then fetch
app.MapPost("/hooks/mailcycle", async (HttpRequest request) =>
{
    using var reader = new StreamReader(request.Body);
    var raw = await reader.ReadToEndAsync(); // the body exactly as it arrived
    if (!WebhookSignature.VerifyNow(secret, raw, request.Headers["Mailcycle-Signature"]))
        return Results.Unauthorized();

    var ev = JsonNode.Parse(raw)!;
    if ((string?)ev["type"] == "message.received")
    {
        var message = await mc.Messages.GetAsync((string)ev["payload"]!["messageId"]!);
        await HandleAsync(message.Subject, message.Text);
    }
    return Results.NoContent();
});
No mail server

Instead of SmtpClient or MailKit and a mailbox.

Microsoft's own documentation steers new code away from System.Net.Mail.SmtpClient, and MailKit, the usual replacement, still needs an SMTP server to send through and an IMAP mailbox with a password to read from.

Here an address is one awaited call, mail arrives on a webhook or through WaitForAsync, and each message comes back parsed into a record: sender, subject, Text, SafeHtml with remote content removed, and attachments as byte arrays.

Sending is built for answering the mail your addresses receive, within your plan's daily limit.

Encrypted on arrival

Mail is encrypted the moment it arrives and opened in your .NET code.

Each address has a key pair derived from your recovery phrase. Incoming mail is sealed to its public key before anything is written down, and the package derives the private key on your machine to open it.

How the encryption works
  • Signing in proves you hold the key by answering a challenge, so the phrase never crosses the wire.
  • Bodies, attachments, address labels and API key names are all sealed. The server stores ciphertext.
  • Mail sealed by one SDK opens in every other, and in the app, because they share one published format.
  • The package is checked against Mailcycle's published test vectors, including the cases that must be refused.
  • Search runs on your device, where mail is decrypted.
Use cases

What developers build with the .NET SDK.

It runs in ASP.NET Core apps, Worker Services, Azure Functions and console tools: anywhere .NET code needs an email address of its own.

End-to-end tests for sign-up and login

Verification emails, one-time passcodes, magic links, password resets and invitations, checked by a real test in xUnit, NUnit, MSTest and Playwright for .NET.

A support or orders inbox your code answers

Give an address to a queue, read what customers send, and reply from the address they wrote to, threaded under their message.

Receipts, invoices and alerts as data

Point suppliers, monitoring and other services at an address and pull the text and attachments straight into your own records.

An address per customer, job or device

Mint addresses on demand and keep each stream of mail separate, with its own label, and delete one when the job is done.

Building an AI agent? It can have an inbox too, through the Mailcycle MCP server, without writing any .NET at all.

The package

C# and .NET SDK at a glance.

Maintained by Mailcycle, the team that runs the API.

The Mailcycle .NET SDK at a glance
PackageMailcycle
RegistryNuGet
Install withdotnet CLI or the NuGet package manager
Needs.NET 8 or later
AlsoEvery call is async and takes an optional CancellationToken.
LicenceApache 2.0, free to use in your own applications
APIJSON over HTTPS at api.mailcycle.email
GuideThe .NET guide in the docs
GuidesSend email from .NETReceive email in .NET

What each plan unlocks. Free receives mail. A signed-in session sends from Personal up. API keys and webhooks start at Operator, and sending from an API key at Scale. See pricing.

Questions

C# and .NET email SDK questions.

Run dotnet add package Mailcycle, sign in with MailcycleClient.SignInAsync, and create an address with mc.Addresses.CreateAsync(). Mail sent to it is stored encrypted, and mc.Messages.AllAsync() or mc.Messages.WaitForAsync() returns it decrypted and parsed. No SMTP server, no IMAP mailbox.

Yes. The Mailcycle email API is JSON over HTTPS, and the Mailcycle package on NuGet wraps it for C# with async methods for addresses, incoming mail, sending, webhooks and the event stream. It also derives the keys from your recovery phrase and opens each message in your process.

Create an address with the C# email API and its mail is stored for you. await mc.Messages.AllAsync(addressId) returns what has arrived, and each Message carries FromAddress, Subject, Text, Html, SafeHtml and Attachments. There is no mailbox password and no IMAP connection to keep open.

Register a webhook for message.received and map a POST endpoint, as in the minimal API example on this page. Check the Mailcycle-Signature header with WebhookSignature.VerifyNow, then fetch the message by id with mc.Messages.GetAsync. Webhooks are on Operator and above; a Worker Service can await WaitForAsync instead.

Each Message lists its files in Attachments, with Index, Filename, MimeType and Size. await mc.Messages.AttachmentAsync(message, file.Index) returns the bytes, decrypted on your machine, ready for File.WriteAllBytesAsync or blob storage.

Call await mc.Messages.SendAsync(new Outgoing(from, to, subject, text)) with an address your account owns. Set ReplyTo to the message you are answering and the threading headers are filled in. Sending from a signed-in session works from the Personal plan, and from an API key on Scale and above.

.NET 8 or later. Every method is asynchronous and takes an optional CancellationToken, and MailcycleOptions sets the API address and the request timeout.

The package is free and open source under the Apache 2.0 licence. The Mailcycle Free plan costs nothing and needs no card: 3 email addresses and 3,000 messages received a month, receive only. Sending starts on Personal at $7 a month, API keys and webhooks on Operator at $15, and sending from an API key on Scale at $19.

Incoming mail is encrypted to the address's public key the moment it arrives, and the private key is derived from your recovery phrase inside your .NET process. Mail you send leaves in plain text so the recipient's server can read it, and the copy kept in Sent is sealed like the rest.

Call mc.Addresses.CreateAsync() at the start of the run and delete the address at the end, which frees its place on your plan. Each address receives mail as soon as it exists. This is for testing your own product and for mail meant for you: registering accounts on other services in bulk, or against their terms, breaks the Acceptable Use Policy.

Up to 60 messages an hour per account and 20 an hour per device or agent (more on Fleet and Enterprise), within your plan's daily limit. The Acceptable Use Policy covers what may be sent.

The API is plain JSON over HTTPS at api.mailcycle.email, so anything can call it. Message content comes back encrypted, though, and the package is what derives the keys and opens it. Without an SDK you would implement the published encryption format yourself.

Give your .NET code an email address.

Create an account, create an address, and read what arrives. The free tier needs no card.