.NET
Use the official Lettermint .NET SDK to send email from a C# application. The SDK also supports the Team API and webhook signature verification. See SDKs and integrations for other packages.
Requirements
Before you start, you need:
- The .NET SDK for your application, targeting .NET 8 or newer
- A Lettermint account with a verified sending domain
- A Project API token from your project settings
1. Installation
Install the Lettermint NuGet package from your application directory:
Code
The package includes targets for .NET 8 and .NET 10.
2. Send your first email
Set LETTERMINT_PROJECT_TOKEN in your application's environment. Use a Project API token for email sends.
Add this code to a console application's Program.cs:
Code
Replace the sender with an address on your verified domain. Replace the recipient with your test address, then run the application:
Code
Keep the email client for repeated requests. Dispose it when your application no longer needs it. Each email.From(...) or email.Compose() call creates a new email builder. Use a new builder for each email. Do not share a builder between concurrent sends.
3. Email options
The examples below use the email client from the previous section.
Recipients, reply-to, and headers
Code
Headers sets email headers. Use IdempotencyKey for the HTTP idempotency header.
Tags and metadata
Code
Use Tags for named tags or Tag("order-confirmation") for a single tag. Metadata values must be strings. Lettermint includes metadata in webhook payloads so you can connect delivery events to application records. See tags for tag options.
Route and delivery settings
Code
Route selects a route by its slug. TlsPolicy.Enforced requires TLS for email delivery. See TLS for delivery behavior.
Idempotency
Set a key to prevent duplicate emails when your application repeats a send:
Code
Use the same key when you retry the same email. The SDK does not retry requests automatically. See idempotency for the API rules and retention window.
File attachments
Read the file and encode its content as Base64:
Code
For an inline image, pass contentId to Attach and use the matching cid: reference in the HTML body. See inline images.
Scheduled emails
Use a future timestamp with an explicit time zone:
Code
The client also provides RescheduleAsync and CancelAsync. See email scheduling for scheduling limits and cancellation behavior.
4. Responses and errors
SendAsync() returns a typed response with MessageId and Status. API acceptance does not confirm delivery. Use webhooks to receive delivery and bounce events.
Catch API failures before other SDK failures:
Code
LettermintApiException also exposes ResponseBody, with the token removed. Other SDK failures, including network, timeout, and response parsing failures, use LettermintException. If you cancel a request with a CancellationToken, it throws OperationCanceledException.
To change the default request timeout, pass ClientOptions when you create the client:
Code
Team API
Use a separate Team API token to manage team resources. Set it in LETTERMINT_TEAM_TOKEN:
Code
Do not use a Team API token with the email client. See the Team API quickstart for token setup and permissions.
Track delivery, opens, and bounces
Enable tracking on your sending route to record opens and clicks. Subscribe to webhooks for delivery and bounce events.
The SDK provides Webhook.Verify(rawBody, signatureHeader, signingSecret) to verify webhook signatures. Pass the original request body without changes. Invalid signatures throw WebhookVerificationException. See webhook signature verification for the header and signing secret.
Next steps
Tags
Organize emails with tags.
Webhooks
Receive delivery and bounce events.
Test addresses
Test delivery and bounce handling.
Team API
Manage team resources.
GitHub repository
Read the source code or report an issue.