Custodian.Infobip.Email
1.0.1
dotnet add package Custodian.Infobip.Email --version 1.0.1
NuGet\Install-Package Custodian.Infobip.Email -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Custodian.Infobip.Email" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Custodian.Infobip.Email" Version="1.0.1" />
<PackageReference Include="Custodian.Infobip.Email" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Custodian.Infobip.Email --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Custodian.Infobip.Email, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Custodian.Infobip.Email@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Custodian.Infobip.Email&version=1.0.1
#tool nuget:?package=Custodian.Infobip.Email&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Custodian.Infobip.Email
A simple .NET client for the Infobip Email API, designed for dependency injection, HttpClientFactory
, and resilience.
Quickstart
dotnet add package Custodian.Infobip.Email
1. Register Client
In your Program.cs
or Startup.cs
, register the client with the dependency injection container.
using Custodian.Infobip.Email.DependencyInjection;
using Custodian.Infobip.Email.Options;
builder.Services.AddInfobipEmailClient(o =>
{
// The base URL for your Infobip account
o.BaseUrl = new Uri("https://xxxxx.api.infobip.com");
// Your Infobip API Key
o.ApiKey = Environment.GetEnvironmentVariable("INFOBIP_API_KEY");
});
2. Send Email
Inject IInfobipEmailClient
into your service or controller and use the SendAsync
method.
using Custodian.Infobip.Email;
using Custodian.Infobip.Email.Models;
// Inject the client via constructor
public class MyService(IInfobipEmailClient emailClient)
{
public async Task SendWelcomeEmailAsync(string userEmail, string userName)
{
var request = new ClientEmailMessageRequest
{
From = "donotreply@mycompany.com",
Subject = "Welcome!",
HtmlBody = "<b>Hello and welcome!</b><p>We are glad to have you.</p>",
ToReceipient =
{
new EmailRecipient(userEmail, userName)
}
// You can also add attachments here
};
try
{
var response = await emailClient.SendAsync(request);
if (response.IsSuccess)
{
Console.WriteLine("Email sent successfully!");
}
else
{
// Handle cases where the API accepted the request but reported an error
Console.WriteLine($"API failed to send email with status {response.StatusCode}.");
Console.WriteLine($"Response: {response.ResponseBody}");
}
}
catch (HttpRequestException ex)
{
// Handle network or non-success HTTP status code errors
Console.WriteLine($"An HTTP error occurred: {ex.Message}");
}
}
}
Configuration
The AddInfobipEmailClient
method configures the client using the following options:
BaseUrl
(required): The base URL for your Infobip account, e.g.,https://{your-subdomain}.api.infobip.com
.ApiKey
(required): Your Infobip API Key. The client will useAuthorization: App {ApiKey}
.SendEndpointPath
: The path for sending emails. Defaults to/email/4/messages
.Timeout
: The overall request timeout for the HttpClient. Defaults to 100 seconds.
Responses and Errors
- If the Infobip API returns a non-success status code (like 4xx or 5xx), the client will log the error and throw an
HttpRequestException
. - On a successful HTTP response, the client returns an
EmailMessageResponse
object with the following properties:IsSuccess
(bool): Indicates if the HTTP request was successful.StatusCode
(int): The HTTP status code of the response.ResponseBody
(string): The raw JSON body of the response from the API.
Building the package
dotnet build -c Release
dotnet pack src/Custodian.Infobip.Email/Custodian.Infobip.Email.csproj -c Release -o ./nupkgs
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Polly (>= 8.3.1)
- Polly.Extensions.Http (>= 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.