The SDK for sendflare service written in C#.
- .NET Standard 2.0 or higher
- .NET Framework 4.6.1+ / .NET Core 2.0+ / .NET 8.0+
Install via NuGet Package Manager:
dotnet add package Sendflare.SDKOr via Package Manager Console:
Install-Package Sendflare.SDKusing Sendflare.SDK;
using Sendflare.SDK.Models;
var client = new SendflareClient("your-api-token");
var req = new SendEmailReq
{
From = "test@example.com",
To = "to@example.com",
Subject = "Hello",
Body = "Test email"
};
try
{
var response = await client.SendEmailAsync(req);
Console.WriteLine($"Email sent successfully: {response.Success}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}using Sendflare.SDK;
using Sendflare.SDK.Models;
var client = new SendflareClient("your-api-token");
var req = new SendEmailReq
{
From = "sender@example.com",
To = "recipient@example.com",
Subject = "Subject Here",
Body = "Email body content"
};
var response = await client.SendEmailAsync(req);
if (response.Success)
{
Console.WriteLine("Email sent successfully!");
}using Sendflare.SDK;
using Sendflare.SDK.Models;
var client = new SendflareClient("your-api-token");
var req = new ListContactReq
{
AppId = "your-app-id",
Page = 1,
PageSize = 10
};
var response = await client.GetContactListAsync(req);
Console.WriteLine($"Total contacts: {response.TotalCount}");
foreach (var contact in response.Data)
{
Console.WriteLine($"Email: {contact.EmailAddress}");
}using Sendflare.SDK;
using Sendflare.SDK.Models;
using System.Collections.Generic;
var client = new SendflareClient("your-api-token");
var req = new SaveContactReq
{
AppId = "your-app-id",
EmailAddress = "john@example.com",
Data = new Dictionary<string, string>
{
{ "firstName", "John" },
{ "lastName", "Doe" },
{ "company", "Acme Corp" }
}
};
var response = await client.SaveContactAsync(req);
if (response.Success)
{
Console.WriteLine("Contact saved successfully!");
}using Sendflare.SDK;
using Sendflare.SDK.Models;
var client = new SendflareClient("your-api-token");
var req = new DeleteContactReq
{
EmailAddress = "john@example.com",
AppId = "your-app-id"
};
var response = await client.DeleteContactAsync(req);
if (response.Success)
{
Console.WriteLine("Contact deleted successfully!");
}public SendflareClient(string token)Create a new Sendflare client instance.
Parameters:
token- Your Sendflare API token
public async Task<SendEmailResp> SendEmailAsync(SendEmailReq req)Send an email.
Parameters:
req- Send email requestFrom- Sender email addressTo- Recipient email addressSubject- Email subjectBody- Email body content
Returns: Task<SendEmailResp>
public async Task<ListContactResp> GetContactListAsync(ListContactReq req)Get contact list with pagination.
Parameters:
req- List contact requestAppId- Application IDPage- Page numberPageSize- Items per page
Returns: Task<ListContactResp>
public async Task<SaveContactResp> SaveContactAsync(SaveContactReq req)Create or update a contact.
Parameters:
req- Save contact requestAppId- Application IDEmailAddress- Contact email addressData- Contact data (Dictionary<string, string>)
Returns: Task<SaveContactResp>
public async Task<DeleteContactResp> DeleteContactAsync(DeleteContactReq req)Delete a contact.
Parameters:
req- Delete contact requestEmailAddress- Contact email addressAppId- Application ID
Returns: Task<DeleteContactResp>
SendEmailReq- Send email requestListContactReq- Get contact list requestSaveContactReq- Save contact requestDeleteContactReq- Delete contact requestPaginateReq- Pagination request (base class)
SendEmailResp- Send email responseListContactResp- Get contact list responseSaveContactResp- Save contact responseDeleteContactResp- Delete contact responseCommonResponse<T>- Common response (base class)PaginateResp- Pagination response (base class)ContactItem- Contact information
# Restore dependencies
dotnet restore
# Build the solution
dotnet build
# Run tests
dotnet test
# Pack NuGet package
dotnet pack -c ReleaseRun tests with:
dotnet testAll async methods may throw exceptions. It's recommended to wrap calls in try-catch blocks:
try
{
var response = await client.SendEmailAsync(req);
// Handle success
}
catch (HttpRequestException ex)
{
// Handle HTTP errors
Console.WriteLine($"HTTP error: {ex.Message}");
}
catch (Exception ex)
{
// Handle other errors
Console.WriteLine($"Error: {ex.Message}");
}All API methods are asynchronous and return Task<T>. Make sure to use await when calling them:
// Good
var response = await client.SendEmailAsync(req);
// Don't do this
var response = client.SendEmailAsync(req).Result; // May cause deadlocksThe SendflareClient implements IDisposable. It's recommended to use it with using statement:
using (var client = new SendflareClient("your-token"))
{
var response = await client.SendEmailAsync(req);
}
// Client is automatically disposed here- System.Text.Json (>= 6.0.0) - JSON serialization
For more information, visit: https://docs.sendflare.com