Send ASP.NET email without hiding delivery behind a background job. Queue it, trace it, and act on the result.
Call one email API from your existing .NET service, retain the message ID, and follow each transactional or lifecycle email through delivery.
✓Keep the key in user-secrets locally and your configuration provider in production.
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 / 03 ]Integration shape
Put email where ASP.NET already handles trusted work.
Use minimal APIs, controllers, and hosted services
Use a controller for immediate application calls or a BackgroundService for durable work outside the request path.
Publish product events
Publish signup, trial, and payment events from the service that commits them, so flows react to durable state.
Verify the webhook
A minimal API endpoint reading the raw body from HttpRequest.Body before model binding.
[ 02 / 03 ]Server quickstart
Queue an ASP.NET email with a stable retry key.
The accepted response gives your service a message ID; the idempotency key protects the same logical send from retries.
Reuse an injected HttpClient and set a stable idempotency key per message.
using var request = new HttpRequestMessage(HttpMethod.Post, EmailUrl);
request.Headers.Authorization = new("Bearer", apiKey);
request.Headers.Add("Idempotency-Key", $"welcome-{user.Id}");
request.Content = JsonContent.Create(new { to = user.Email, template = "welcome" });
var response = await http.SendAsync(request);
response.EnsureSuccessStatusCode();Accepted response
{ "id": "msg_7ca31", "status": "queued" }[ 03 / 03 ]Related
Keep building with ASP.NET
Questions people ask us
Give your next ASP.NET email a delivery trail.
Queue one real message, keep its ID, and verify the event that closes the loop.