MisarMisar Docs
MisarMailMisarBlogMisarReachMisarPostMisarDevMisarCoderMisarSEOMisar PlatformMisar SSO
SDKs

C# SDK

Install and use the MisarMail C# SDK

Installation

dotnet add package Misar.Mail

Or via the NuGet Package Manager:

Install-Package Misar.Mail

Quick Start

using Misar.Mail;

var client = new MisarMailClient(Environment.GetEnvironmentVariable("MISARMAIL_API_KEY")!);

var result = await client.Email_SendAsync(new
{
    from = new { email = "hello@misar.io", name = "Misar" },
    to = new[] { new { email = "user@example.com" } },
    subject = "Welcome",
    html = "<p>Hello from MisarMail!</p>",
});

Console.WriteLine($"Sent: {result.GetProperty("message_id")}");

Configuration

var client = new MisarMailClient(
    apiKey: Environment.GetEnvironmentVariable("MISARMAIL_API_KEY")!,
    baseUrl: "https://api.misar.io/mail/v1",  // Default
    maxRetries: 3                              // Default: 3
);

Available Methods

Methods are flat on the client (client.Resource_MethodAsync(...)). Payloads are plain objects (anonymous objects or Dictionary<string, object>) and every call returns Task<JsonElement>. All async methods accept an optional trailing CancellationToken ct.

MethodDescription
client.Email_SendAsync(payload, ct)Send a transactional email
client.Contacts_ListAsync(queryParams, ct)List contacts
client.Contacts_CreateAsync(payload, ct)Create a contact
client.Contacts_GetAsync(id, ct)Get a contact
client.Contacts_UpdateAsync(id, payload, ct)Update a contact
client.Contacts_DeleteAsync(id, ct)Delete a contact
client.Contacts_ImportContactsAsync(payload, ct)Bulk import contacts
client.Campaigns_ListAsync(queryParams, ct)List campaigns
client.Campaigns_CreateAsync(payload, ct)Create a campaign
client.Campaigns_GetAsync(id, ct)Get a campaign
client.Campaigns_UpdateAsync(id, payload, ct)Update a campaign
client.Campaigns_SendCampaignAsync(id, ct)Send/schedule a campaign
client.Campaigns_DeleteAsync(id, ct)Delete a campaign
client.Templates_ListAsync(ct)List templates
client.Templates_CreateAsync(payload, ct)Create a template
client.Templates_GetAsync(id, ct)Get a template
client.Templates_UpdateAsync(id, payload, ct)Update a template
client.Templates_DeleteAsync(id, ct)Delete a template
client.Templates_RenderAsync(payload, ct)Render a template with merge data
client.Automations_ListAsync(queryParams, ct)List automations
client.Automations_CreateAsync(payload, ct)Create an automation
client.Automations_GetAsync(id, ct)Get an automation
client.Automations_UpdateAsync(id, payload, ct)Update an automation
client.Automations_DeleteAsync(id, ct)Delete an automation
client.Automations_ActivateAsync(id, active, ct)Activate/deactivate an automation
client.Domains_ListAsync(ct)List sending domains
client.Domains_CreateAsync(payload, ct)Add a sending domain
client.Domains_GetAsync(id, ct)Get a domain
client.Domains_VerifyAsync(id, ct)Trigger domain DNS verification
client.Domains_DeleteAsync(id, ct)Delete a domain
client.Aliases_ListAsync(ct)List email aliases
client.Aliases_CreateAsync(payload, ct)Create an alias
client.Aliases_GetAsync(id, ct)Get an alias
client.Aliases_UpdateAsync(id, payload, ct)Update an alias
client.Aliases_DeleteAsync(id, ct)Delete an alias
client.DedicatedIPs_ListAsync(ct)List dedicated IPs
client.DedicatedIPs_CreateAsync(payload, ct)Purchase a dedicated IP
client.DedicatedIPs_UpdateAsync(id, payload, ct)Update IP pool assignment
client.DedicatedIPs_DeleteAsync(id, ct)Release a dedicated IP
client.AbTests_ListAsync(ct)List A/B tests
client.AbTests_CreateAsync(payload, ct)Create an A/B test
client.AbTests_GetAsync(id, ct)Get an A/B test
client.AbTests_SetWinnerAsync(id, variantId, ct)Manually set the winning variant
client.Sandbox_SendAsync(payload, ct)Send in sandbox mode
client.Sandbox_ListAsync(queryParams, ct)List sandbox messages
client.Sandbox_DeleteAsync(id, ct)Delete a sandbox message
client.Inbound_ListAsync(queryParams, ct)List inbound routing rules
client.Inbound_CreateAsync(payload, ct)Create an inbound route
client.Inbound_GetAsync(id, ct)Get an inbound route
client.Inbound_DeleteAsync(id, ct)Delete an inbound route
client.Analytics_OverviewAsync(queryParams, ct)Get send/open/click/bounce analytics
client.Track_EventAsync(payload, ct)Track a custom event
client.Track_PurchaseAsync(payload, ct)Track a purchase event
client.Keys_ListAsync(ct)List API keys
client.Keys_CreateAsync(payload, ct)Create an API key
client.Keys_GetAsync(id, ct)Get an API key
client.Keys_RevokeAsync(id, ct)Revoke an API key
client.Validate_EmailAsync(address, ct)Validate an email address
client.Webhooks_ListAsync(ct)List webhooks
client.Webhooks_CreateAsync(payload, ct)Create a webhook endpoint
client.Webhooks_GetAsync(id, ct)Get a webhook
client.Webhooks_UpdateAsync(id, payload, ct)Update a webhook
client.Webhooks_DeleteAsync(id, ct)Delete a webhook
client.Webhooks_TestAsync(id, ct)Send a test event to a webhook
client.Usage_GetAsync(queryParams, ct)Get API usage stats
client.Billing_SubscriptionAsync(ct)Get current subscription details
client.Billing_CheckoutAsync(payload, ct)Create a billing checkout session
client.Workspaces_ListAsync(ct)List workspaces
client.Workspaces_CreateAsync(payload, ct)Create a workspace
client.Workspaces_GetAsync(id, ct)Get a workspace
client.Workspaces_UpdateAsync(id, payload, ct)Update a workspace
client.Workspaces_DeleteAsync(id, ct)Delete a workspace
client.Workspaces_ListMembersAsync(wsId, ct)List workspace members
client.Workspaces_InviteMemberAsync(wsId, payload, ct)Invite a member to workspace
client.Workspaces_UpdateMemberAsync(wsId, userId, payload, ct)Update member role
client.Workspaces_RemoveMemberAsync(wsId, userId, ct)Remove a member from workspace

Examples

Webhooks

var webhook = await client.Webhooks_CreateAsync(new
{
    url = "https://yourapp.com/webhooks/mail",
    events = new[] { "email.delivered", "email.opened", "email.bounced" },
});
await client.Webhooks_TestAsync(webhook.GetProperty("id").GetString()!);

Error Handling

try
{
    await client.Email_SendAsync(payload);
}
catch (MisarMailException ex)
{
    Console.Error.WriteLine($"{ex.Status}: {ex.Message}");
}