.NET

.NET 9 client built on HttpClient. All operations are async.

Install

dotnet add package Sevk

Initialize

Instantiate SevkClient with your API key.

using Sevk;
var sevk = new SevkClient("sevk_full_xxxxxxxx");

Send Email

HTML body

using Sevk;
using Sevk.Types;
var sevk = new SevkClient("sevk_full_xxxxxxxx");
var response = await sevk.Emails.SendAsync(new SendEmailRequest
{
From = "sevk <[email protected]>",
Subject = "Welcome",
Html = "<h1>Welcome</h1><p>Thanks for signing up.</p>",
ReplyTo = "[email protected]"
});
if (response is SingleEmailResponse email)
Console.WriteLine(email.Id);

With attachments

var pdf = new EmailAttachment
{
Filename = "invoice.pdf",
Content = base64Pdf,
ContentType = "application/pdf"
};
await sevk.Emails.SendAsync(new SendEmailRequest
{
From = "sevk <[email protected]>",
Subject = "Your invoice",
Html = "<p>Invoice attached.</p>",
Attachments = new List<EmailAttachment> { pdf }
});

Send Bulk

var result = await sevk.Emails.SendBulkAsync(new BulkEmailRequest
{
Emails = new List<BulkEmailItemRequest>
{
new() { From = "sevk <[email protected]>", To = "[email protected]", Subject = "Welcome", Html = "<p>Hi 1</p>" },
new() { From = "sevk <[email protected]>", To = "[email protected]", Subject = "Welcome", Html = "<p>Hi 2</p>" }
}
});
Console.WriteLine($"{result.Success} / {result.Failed}");

Contacts

using Sevk.Types;
var contact = await sevk.Contacts.CreateAsync("[email protected]", new CreateContactRequest
{
Subscribed = true,
Data = new Dictionary<string, object> { ["firstName"] = "John", ["plan"] = "pro" }
});
await sevk.Contacts.GetAsync(contact.Id);
await sevk.Contacts.UpdateAsync(contact.Id, new UpdateContactRequest
{
Data = new Dictionary<string, object> { ["plan"] = "enterprise" }
});
var page = await sevk.Contacts.ListAsync(new ListContactsParams { Limit = 50 });
foreach (var c in page.Items) Console.WriteLine(c.Email);
await sevk.Contacts.DeleteAsync(contact.Id);

Audiences

var audience = await sevk.Audiences.CreateAsync(new CreateAudienceRequest
{
Name = "Newsletter"
});
await sevk.Audiences.AddContactsAsync(audience.Id, new List<string>
{
"b2c3d4e5-f678-4901-abcd-ef1234567890",
"b2c3d4e5-f678-4901-abcd-ef1234567891"
});
var contacts = await sevk.Audiences.ListContactsAsync(audience.Id);
foreach (var c in contacts.Items) Console.WriteLine(c.Email);

Error Handling

using Sevk;
try
{
await sevk.Emails.SendAsync(new SendEmailRequest
{
To = "not-an-email",
Subject = "Test",
Text = "Hi"
});
}
catch (SevkException e)
{
if (e.IsValidationError) Console.Error.WriteLine($"validation: {e.Message}");
else if (e.IsUnauthorized) Console.Error.WriteLine("bad api key");
else Console.Error.WriteLine($"{e.StatusCode}: {e.Message}");
}