Easy.Notifications 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Easy.Notifications --version 1.1.0
                    
NuGet\Install-Package Easy.Notifications -Version 1.1.0
                    
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="Easy.Notifications" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Easy.Notifications" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Easy.Notifications" />
                    
Project file
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 Easy.Notifications --version 1.1.0
                    
#r "nuget: Easy.Notifications, 1.1.0"
                    
#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 Easy.Notifications@1.1.0
                    
#: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=Easy.Notifications&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Easy.Notifications&version=1.1.0
                    
Install as a Cake Tool

Build & Test Build & Release Build & Nuget Publish Release License NuGet

Easy.Notifications

Easy.Notifications is a high-performance, asynchronous, and channel-agnostic notification library for .NET 6+.

It is designed for Enterprise applications that need to send notifications (Email, SMS, Chat, Push) without blocking the main execution thread. It leverages System.Threading.Channels to implement a robust "Fire-and-Forget" architecture.

🚀 Features

  • ** Asynchronous & Non-Blocking:** Uses high-performance in-memory queues to dispatch messages instantly.

  • ** Multi-Channel Support:** Unified API for:

    • Email: SMTP, SendGrid, Mailgun.

    • SMS / WhatsApp: Twilio, Vonage (Nexmo).

    • Chat: Slack (Block Kit), Microsoft Teams (Message Cards), Telegram.

    • Realtime: SignalR (WebSockets).

  • ** Rich Content Support:** - Automatically converts messages to Slack Block Kit structures.

    • Renders Microsoft Teams Message Cards with custom colors and sections.
  • ** Modular Architecture:** Add only the providers you need via Dependency Injection.

  • ** Built-in Templating:** Lightweight template engine for dynamic content (Hello {{Name}}).

Architecture

The library separates the Dispatching logic from the Processing logic to ensure maximum throughput.

  1. Producer: Your Controller calls INotificationService.SendAsync().

  2. Dispatcher: The payload is instantly written to a memory channel. Control returns to your code in microseconds.

  3. Worker: A background service (BackgroundNotificationWorker) reads from the channel.

  4. Provider: The specific provider (e.g., SlackProvider, SmtpEmailProvider) executes the external API call safely.

📦 Installation

Install via NuGet Package Manager:

Install-Package Easy.Notifications

Or via .NET CLI:

dotnet add package Easy.Notifications

Configuration

1. appsettings.json

Configure only the providers you intend to use.

{
  "NotificationConfiguration": {
    "EmailConfiguration": {
      "Host": "smtp.example.com",
      "Port": 587,
      "Username": "apikey",
      "Password": "secret-password",
      "Sender": "no-reply@example.com",
      "SenderDisplayName": "System Alerts",
      "EnableSsl": true
    },
    "TwilioConfiguration": {
      "AccountSid": "ACxxxxxxxx...",
      "AuthToken": "xxxxxxxx...",
      "FromNumber": "+15551234567"
    },
    "SendGridConfiguration": {
      "ApiKey": "SG.xxxxxxxx...",
      "SenderEmail": "alert@example.com",
      "SenderName": "Alert Bot"
    },
    "VonageConfiguration": {
      "ApiKey": "a1b2c3d4",
      "ApiSecret": "xxxxxxxxxxxx",
      "Sender": "MyBrand"
    },
    "MailgunConfiguration": {
      "ApiKey": "<MAILGUN_API_KEY>",
      "Domain": "<MAILGUN_DOMAIN>",
      "SenderEmail": "noreply@example.com",
      "SenderName": "Easy Notifications"
    },
    "TelegramConfiguration": {
      "BotToken": "123456:ABC-DEF..."
    }
  }
}

2. Service Registration (Program.cs)

Register the core services and the specific providers you need.

using Easy.Notifications.Extensions;

var builder = WebApplication.CreateBuilder(args);

// 1. Add Core Services (Dispatcher, Worker)
builder.Services.AddEasyNotifications();

// 2. Add Desired Providers (Modular Registration)
// Email
builder.Services.AddSmtpEmail(builder.Configuration);

// SMS & WhatsApp
builder.Services.AddTwilio(builder.Configuration);

// Chat Apps (Slack, Teams, Telegram)
builder.Services.AddChatProviders(builder.Configuration);

// Realtime
builder.Services.AddSignalRNotifications();

var app = builder.Build();

// 3. Map SignalR Hub (If using Realtime)
app.MapHub<NotificationHub>("/notifications");

app.Run();

Usage

Inject INotificationService into your controllers or business services.

Example 1: Sending Rich Slack & Teams Messages

Send structured messages with colors, headers, and metadata without dealing with complex JSON payloads.

public class AlertController : ControllerBase
{
    private readonly INotificationService _notifier;

    public AlertController(INotificationService notifier)
    {
        _notifier = notifier;
    }

    [HttpPost("alert")]
    public async Task<IActionResult> SendAlert()
    {
        var slackUrl = "https://hooks.slack.com/services/T000/B000/XXXX";
        var teamsUrl = "https://your-teams-webhook-url";

        var payload = new NotificationPayload
        {
            Subject = "High CPU Usage Warning 🚨",
            Body = "Server **Prod-01** CPU usage is at *98%*. Please investigate immediately.",
            
            Recipients = new List<Recipient>
            {
                Recipient.Chat(slackUrl, NotificationChannelType.Slack),
                Recipient.Chat(teamsUrl, NotificationChannelType.Teams)
            },

            // Metadata creates "Context" in Slack and "Fact Section" in Teams
            Metadata = new Dictionary<string, object>
            {
                { "ThemeColor", "FF0000" }, // Red card for Teams
                { "Server", "Linux-Prod-01" },
                { "Region", "US-East-1" },
                { "Time", DateTime.Now.ToString("HH:mm") }
            }
        };

        // Fire-and-Forget
        await _notifier.SendAsync(payload);

        return Ok("Alert queued.");
    }
}

Example 2: Multi-Channel Broadcast (Email + SMS)

var payload = new NotificationPayload
{
    Subject = "Welcome {{Name}}",
    Body = "Hi {{Name}}, your account is activated.",
    TemplateData = new Dictionary<string, string> { { "Name", "John Doe" } },
    
    Recipients = new List<Recipient>
    {
        Recipient.Email("john@example.com", "John Doe"),
        Recipient.Sms("+15550001234"),
        Recipient.WhatsApp("+15550001234")
    }
};

await _notifier.SendAsync(payload);

Example 3: Real-Time Web Notification (SignalR)

var payload = new NotificationPayload
{
    Subject = "Export Complete",
    Body = "Your data export is ready to download.",
    Recipients = new List<Recipient>
    {
        Recipient.Client("user-123-id") // Targets a specific user on frontend
    }
};

await _notifier.SendAsync(payload);

Supported Providers

Channel Provider Class NuGet Dependency Notes
Email SmtpEmailProvider Built-in Standard .NET SmtpClient
Email SendGridProvider SendGrid Uses SendGrid Web API
Email MailgunProvider Microsoft.Extensions.Http Uses Mailgun API v3
SMS TwilioSmsProvider Twilio Standard SMS
SMS VonageSmsProvider Built-in Uses Nexmo/Vonage REST API
WhatsApp TwilioWhatsAppProvider Twilio Requires WhatsApp Sandbox/Number
Slack SlackProvider Built-in Uses Incoming Webhooks (Block Kit)
Teams TeamsProvider Built-in Uses Incoming Webhooks (MessageCard)
Telegram TelegramProvider Built-in Uses Telegram Bot API
Realtime SignalRProvider Microsoft.AspNetCore.SignalR.Core Pushes to connected clients

Extending

You can easily add your own provider (e.g., Discord, Firebase FCM) by implementing INotificationProvider.

  1. Create a class implementing INotificationProvider.

  2. Define the SupportedChannel.

  3. Implement SendAsync.

  4. Register it in DI: services.TryAddEnumerable(ServiceDescriptor.Singleton<INotificationProvider, MyCustomProvider>());


Contributing

Contributions and suggestions are welcome. Please open an issue or submit a pull request.


Contact

For questions, contact us via elmin.alirzayev@gmail.com or GitHub.


License

This project is licensed under the MIT License.


© 2025 Elmin Alirzayev / Easy Code Tools

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 134 2/6/2026
1.1.0 119 2/4/2026
1.0.14 116 1/23/2026
1.0.13 115 1/23/2026
1.0.11 238 8/11/2025
1.0.7 258 8/8/2025
1.0.6 289 8/8/2025
1.0.5 283 8/8/2025

-