Skip to main content

C and C#

The legacy docs list /c twice in the Email API category, and the live /c article is a C/libcurl example, not C#. Keep this page as the canonical redirect target until product and engineering confirm whether separate C and C# pages are needed.

C# pattern

Use HttpClient, send JSON, and pass the API key as a bearer token.

using System.Net.Http.Headers;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://transmission.mailtarget.co/v1/layang/transmissions");

request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("MAILTARGET_API_KEY"));
request.Content = new StringContent("""
{
"subject": "Hello from Mailtarget",
"from": { "email": "you@your-verified-domain.com", "name": "Your Name" },
"to": [{ "email": "recipient@example.com" }],
"bodyText": "If you can read this, the integration works."
}
""", Encoding.UTF8, "application/json");

var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());

C pattern

Use your team's standard HTTP client, such as libcurl, with the same method, URL, headers, and JSON body shown in the cURL example.

Legacy C examples used libcurl with Authorization: Bearer API_KEY, accept: application/json, and Content-Type: application/json.