Cómo enviar correos con .NET / C#
Envía correos desde .NET con `HttpClient` y `PostAsJsonAsync`, llamando a la API REST de Publiq.
No hay SDK oficial — llama a la API REST de Publiq con el cliente HTTP del lenguaje, desde el servidor, con la API key en el header Authorization.
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" }
});Buenas prácticas
- Llama a Publiq siempre desde el servidor — la API key va en el header
Authorization, nunca en el cliente. - En
429/5xx, reintenta con backoff exponencial (respetaRetry-After). - Prefiere
templateKeysobre HTML inline para mantener el contenido versionado. - Maneja los errores por el campo
error.codede la respuesta — ver Errores. - Envía desde un dominio verificado — ver Dominios.