Send emails from C# and .NET
Transactional and marketing email from ASP.NET apps and hosted workers. One HttpClient call, and a message ID you can follow to the inbox.
✓Free to start. Unlimited contacts on every tier.
One request, complete trace
Request
POST /api/v1/emails
Authorization: Bearer aem_…
Idempotency-Key: welcome-8f21
{ "to": "[email protected]", "template": "welcome" }
202 Accepted
{ "id": "msg_7ca31", "status": "queued" }
[ 01 / 04 ]Quickstart
How do I send email from C# and .NET?
Three steps from no account to a queued email. No NuGet package needed.
Create an API key
In the dashboard, open Settings → API & MCP and create a key with the Send + manage permission (the default). It starts with aem_ and is shown once.
Store it as an environment variable
Keep the key on your server. Your code reads it through IConfiguration, which includes environment variables.
Terminalexport AEM_KEY="aem_..."Send the email
POST the recipient and a published template. Here http is an HttpClient and config is IConfiguration. EnsureSuccessStatusCode throws on a 4xx or 5xx, and a retry with the same Idempotency-Key won't send a second email.
EmailService.csvar apiKey = config["AEM_KEY"]; using var request = new HttpRequestMessage(HttpMethod.Post, "https://sendandretain.com/api/v1/emails"); request.Headers.Authorization = new("Bearer", apiKey); request.Headers.Add("Idempotency-Key", $"welcome-{user.Id}"); request.Content = JsonContent.Create(new { to = user.Email, template = "welcome" }); using var response = await http.SendAsync(request); response.EnsureSuccessStatusCode();Keep the message ID
A 202 means queued, not delivered. Store the id; delivery, bounce, and complaint events arrive later on your signed webhook.
202 Accepted{ "id": "msg_7ca31", "status": "queued" }
[ 02 / 04 ]In production
What does a production .NET integration need?
IHttpClientFactory
Register a named or typed client with the base URL, timeout, and key, and inject it where you send.
Retries with the same key
Send after the operation succeeds, or from a hosted worker. Retry timeouts and 5xx errors with the same Idempotency-Key.
Webhooks checked on the raw body
Read HttpRequest.Body before model binding, so the signature check sees the raw payload.
Events for marketing email
Send product events like signup or trial started. Automations you've turned on decide which email goes out.
[ 03 / 04 ]Example prompts
What can you ask your coding agent to do in .NET?
Paste these into Claude Code, Cursor, or Codex. Connect the MCP server and it can build the templates and automations too.
Typed client
“Register a typed HttpClient for the Send & Retain API with IHttpClientFactory and send a welcome email when a user signs up, keyed on the user ID.”
Hosted worker
“Move our email sends into a hosted worker that retries timeouts with the same Idempotency-Key and never retries 4xx errors.”
Webhooks
“Add a minimal API endpoint that verifies Send & Retain webhook signatures on the raw body and flags bounced addresses on our users.”
Trial automation
“Send a trial_started event to Send & Retain when a trial begins, then build a paused trial automation for it.”
Questions people ask us
Send your first email from .NET.
Create a key, make one call, and follow the message ID to the inbox.