Cirreum.Communications.Email.SendGrid 1.0.23

dotnet add package Cirreum.Communications.Email.SendGrid --version 1.0.23
                    
NuGet\Install-Package Cirreum.Communications.Email.SendGrid -Version 1.0.23
                    
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="Cirreum.Communications.Email.SendGrid" Version="1.0.23" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cirreum.Communications.Email.SendGrid" Version="1.0.23" />
                    
Directory.Packages.props
<PackageReference Include="Cirreum.Communications.Email.SendGrid" />
                    
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 Cirreum.Communications.Email.SendGrid --version 1.0.23
                    
#r "nuget: Cirreum.Communications.Email.SendGrid, 1.0.23"
                    
#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 Cirreum.Communications.Email.SendGrid@1.0.23
                    
#: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=Cirreum.Communications.Email.SendGrid&version=1.0.23
                    
Install as a Cake Addin
#tool nuget:?package=Cirreum.Communications.Email.SendGrid&version=1.0.23
                    
Install as a Cake Tool

Cirreum.Communications.Email.SendGrid

NuGet Version NuGet Downloads GitHub Release License .NET

SendGrid email service implementation for the Cirreum communications framework

Overview

Cirreum.Communications.Email.SendGrid provides a robust SendGrid email service implementation for the Cirreum communications framework. It implements the IEmailService interface with comprehensive features for reliable email delivery.

Features

  • Single & Bulk Email Sending - Send individual emails or bulk operations with shared templates or fully personalized messages
  • Retry Logic - Exponential backoff with jitter for handling rate limits and transient failures
  • Template Support - Dynamic template integration with friendly name mapping
  • Attachment Handling - Support for inline and attachment dispositions with streams or byte arrays
  • Health Check Integration - Built-in health monitoring for SendGrid API connectivity
  • Sandbox Mode - Testing mode that processes emails without actual delivery
  • Comprehensive Validation - Email address validation and content verification before sending
  • Dependency Injection - Seamless integration with .NET hosting and service provider

Getting Started

Installation

dotnet add package Cirreum.Communications.Email.SendGrid

Basic Usage

// Register in Program.cs
builder.AddSendGridEmailClient("sendgrid", settings => {
    settings.ApiKey = "your-api-key";
    settings.DefaultFrom = new EmailAddress("noreply@yourcompany.com", "Your Company");
});

// Use in your service
public class NotificationService {
    private readonly IEmailService _emailService;
    
    public NotificationService([FromKeyedServices("sendgrid")] IEmailService emailService) {
        _emailService = emailService;
    }
    
    public async Task SendWelcomeEmailAsync(string to, string name) {
        var message = new EmailMessage {
            To = [new EmailAddress(to, name)],
            Subject = "Welcome!",
            HtmlContent = "<h1>Welcome to our service!</h1>"
        };
        
        var result = await _emailService.SendEmailAsync(message);
    }
}

Bulk Sending

// Shared template approach
var template = new EmailMessage {
    Subject = "Newsletter",
    HtmlContent = "<h1>Latest News</h1>"
};

var recipients = [
    new EmailAddress("user1@example.com", "User One"),
    new EmailAddress("user2@example.com", "User Two")
];

var response = await _emailService.SendBulkEmailAsync(template, recipients);

Configuration Options

builder.AddSendGridEmailClient("sendgrid", settings => {
    settings.ApiKey = "your-api-key";
    settings.DefaultFrom = new EmailAddress("noreply@yourcompany.com");
    settings.MaxRetries = 3;
    settings.SandboxMode = false;
    settings.BulkOptions.MaxBatchSize = 100;
    settings.BulkOptions.MaxConcurrency = 5;
    settings.TemplateMap = new Dictionary<string, string> {
        ["welcome"] = "d-abc123",
        ["reset-password"] = "d-def456"
    };
    settings.GlobalHeaders = new Dictionary<string, string> {
        ["X-Company"] = "YourCompany"
    };
    settings.GlobalCategories = ["transactional"];
});

## Advanced Features

### JSON Connection String Support

For secure configuration management (e.g., Azure Key Vault):

```csharp
var connectionJson = """
{
    "ApiKey": "SG.your-api-key",
    "DefaultFrom": {
        "Address": "noreply@yourcompany.com",
        "Name": "Your Company"
    }
}
""";

builder.AddSendGridEmailClient("sendgrid", connectionJson);

Health Checks

The library includes built-in health checks that verify SendGrid API connectivity:

builder.AddSendGridEmailClient("sendgrid", settings => {
    // ... other settings
}, healthOptions => {
    healthOptions.Enabled = true;
    healthOptions.Timeout = TimeSpan.FromSeconds(10);
});

builder.Services.AddHealthChecks()
    .AddCheck<SendGridEmailHealthCheck>("sendgrid-email");

Template Usage

Use SendGrid dynamic templates with friendly names:

var message = new EmailMessage {
    To = [new EmailAddress("user@example.com")],
    TemplateKey = "welcome", // Maps to template ID via TemplateMap
    TemplateData = new Dictionary<string, object> {
        ["firstName"] = "John",
        ["companyName"] = "Acme Corp"
    }
};

Contribution Guidelines

  1. Be conservative with new abstractions
    The API surface must remain stable and meaningful.

  2. Limit dependency expansion
    Only add foundational, version-stable dependencies.

  3. Favor additive, non-breaking changes
    Breaking changes ripple through the entire ecosystem.

  4. Include thorough unit tests
    All primitives and patterns should be independently testable.

  5. Document architectural decisions
    Context and reasoning should be clear for future maintainers.

  6. Follow .NET conventions
    Use established patterns from Microsoft.Extensions.* libraries.

Versioning

Cirreum.Communications.Email.SendGrid follows Semantic Versioning:

  • Major - Breaking API changes
  • Minor - New features, backward compatible
  • Patch - Bug fixes, backward compatible

License

This project is licensed under the MIT License - see the LICENSE file for details.


Cirreum Foundation Framework
Layered simplicity for modern .NET

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cirreum.Communications.Email.SendGrid:

Package Downloads
Cirreum.Runtime.Communications

The Runtime Communictions service configuration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.23 84 8/4/2026
1.0.22 104 7/30/2026
1.0.21 115 7/20/2026
1.0.20 107 7/19/2026
1.0.19 136 7/4/2026
1.0.18 96 7/4/2026
1.0.17 130 5/7/2026
1.0.16 123 5/1/2026
1.0.15 130 4/28/2026
1.0.14 127 4/26/2026
1.0.12 135 4/14/2026
1.0.11 134 4/10/2026
1.0.10 152 3/13/2026
1.0.9 119 3/12/2026
1.0.8 135 3/9/2026
1.0.7 118 3/6/2026
1.0.6 163 1/22/2026
1.0.5 137 1/21/2026
1.0.4 251 12/25/2025
1.0.3 170 12/20/2025
Loading failed