How to send emails with .NET / C#
Send emails from .NET with `HttpClient` and `PostAsJsonAsync`, calling the Publiq REST API.
There is no official SDK — call the Publiq REST API with your language HTTP client, from the server, with the API key in the Authorization header.
using System.Net.Http;
using System.Net.Http.Json;
var http = new HttpClient();
http.DefaultRequestHeaders.Add(
"Authorization",
$"Bearer {Environment.GetEnvironmentVariable("PUBLIQ_API_KEY")}");
await http.PostAsJsonAsync("https://api.publiq.digital/v1/emails", new {
from = "you@yourdomain.com",
to = "user@example.com",
templateKey = "welcome-email",
variables = new { first_name = "Ana" }
});Best practices
- Always call Publiq from the server — the API key goes in the
Authorizationheader, never on the client. - On
429/5xx, retry with exponential backoff (respectRetry-After). - Prefer
templateKeyover inline HTML to keep content versioned. - Handle errors via the response
error.codefield — see Errors. - Send from a verified domain — see Domains.