Skip to content

Documentation

Send email in .NET.

Works with: .NET 8 or newer. No dependencies.

Install

Get a key under API keys in the dashboard and verify a sending domain first (how). Then add the library:

Terminal
dotnet add package Mailtruss

Send an email

This sends one message and passes an idempotency key, so repeating the request can never deliver it twice. Pass an idempotency key and the same key never sends twice, so a retry after a timeout is safe.

Program.cs
var mt = new Mailtruss.MailtrussClient(Environment.GetEnvironmentVariable("MAILTRUSS_API_KEY")!);
var res = await mt.Emails.SendAsync(new { from = "hello@yourdomain.com", to = "ana@example.com", subject = "Welcome", html = "<p>Hi Ana</p>" }, idempotencyKey: "welcome-ana");

More on what you can put in a message (cc, bcc, attachments, tags, templates, scheduling) is under Sending.

Verify webhook signatures

Mailtruss signs every webhook with the Standard Webhooks scheme. Check the signature before you trust a request. Pass the raw body and a function that reads a header by name.

WebhookController.cs
var ev = Mailtruss.Webhook.Verify(rawBody, name => Request.Headers[name].FirstOrDefault(), secret);

Events, payloads and retries are on the Webhooks page.

Handle errors

Failures are MailtrussException with Name, StatusCode and RequestId. Answers are JsonObject. Every error name, with its cause and fix, is in the error catalogue.

Other languages

Last updated

Something wrong or unclear on this page?

Report an issue