Noundry.Sanquhar

Modern .NET 9 mailing library with Razor template engine and multi-provider support. Send beautiful, dynamic emails with SMTP, SendGrid, or Mailgun.

.NET 9
Modern C# 13
3 Providers
SMTP, SendGrid, Mailgun
Razor
Template Engine
Production
Ready

Why Choose Sanquhar?

Powerful email library designed for .NET developers who need flexible, template-driven email functionality with multiple provider options.

Razor Template Engine

Create dynamic, beautiful HTML emails using familiar Razor syntax with strongly-typed models and full C# support.

Multi-Provider Support

Switch seamlessly between SMTP, SendGrid, and Mailgun with a unified API. No vendor lock-in.

High Performance

Template caching, async/await throughout, and modern .NET 9 optimizations for blazing fast email generation and sending.

Did You Know?

Sanquhar is named after the oldest operating post office in the world, located in Sanquhar, Scotland. It has been continuously operating since 1712—over 310 years of delivering mail!

Get Started in 5 Minutes

Install Sanquhar and start sending beautiful emails with Razor templates.

1. Installation

# Install Sanquhar
$ dotnet add package Noundry.Sanquhar
# Optional: SendGrid or Mailgun
$ dotnet add package Noundry.Sanquhar.SendGrid

2. Configure Services

using
Noundry.Sanquhar.Extensions;
builder.Services.AddSanquhar(builder.Configuration);

3. Send Email

await
_mailService.SendFromTemplateAsync(
"Welcome", model, recipient);
EmailTemplates/Welcome.cshtml
@model WelcomeModel

<!DOCTYPE html>
<html>
<body>
    <h1>Welcome, @Model.Name!</h1>
    <p>
        Thank you for joining on
        @Model.Date.ToString("D").
    </p>
</body>
</html>

Multiple Email Providers

Choose the provider that fits your needs. Switch anytime with minimal code changes.

SMTP (MailKit)

Configuration

Use any SMTP server including Gmail, Outlook, or your own mail server. Built on the reliable MailKit library.

Works with Any SMTP Server

Gmail, Outlook, Office 365, custom servers

SSL/TLS Support

Secure connections with full SSL/TLS support

MailKit Powered

Built on the industry-standard MailKit library

// appsettings.json
{
  "Sanquhar": {
    "TemplatePath": "EmailTemplates",
    "Smtp": {
      "Host": "smtp.gmail.com",
      "Port": 587,
      "Username": "your-email@gmail.com",
      "Password": "your-app-password",
      "EnableSsl": true
    },
    "Mail": {
      "DefaultFrom": "noreply@yourdomain.com"
    }
  }
}

// Program.cs
using Noundry.Sanquhar.Extensions;

builder.Services.AddSanquhar(builder.Configuration);

SendGrid

SendGrid API Integration

Use SendGrid's powerful email API with built-in tracking, analytics, and deliverability features.

Click & Open Tracking

Track email opens and link clicks automatically

Sandbox Mode

Test without sending real emails

Enterprise Ready

High deliverability and scalability

// appsettings.json
{
  "Sanquhar": {
    "SendGrid": {
      "ApiKey": "your-sendgrid-api-key",
      "EnableClickTracking": true,
      "EnableOpenTracking": true,
      "SandboxMode": false
    }
  }
}

// Program.cs
using Noundry.Sanquhar.Extensions;
using Noundry.Sanquhar.SendGrid.Extensions;

builder.Services.AddSanquhar(
    builder.Configuration,
    options => options.UseSendGrid(builder.Configuration)
);

Mailgun

Mailgun API Integration

Powerful email API with excellent deliverability and developer-friendly features. No RestSharp dependency - uses native HttpClient!

No RestSharp Dependency

Built with modern HttpClient and IHttpClientFactory

Email Tracking

Track opens, clicks, and delivery status

Developer Friendly

Great API documentation and debugging tools

// appsettings.json
{
  "Sanquhar": {
    "Mailgun": {
      "ApiKey": "your-mailgun-api-key",
      "Domain": "your-domain.mailgun.org",
      "ApiBaseUrl": "https://api.mailgun.net/v3",
      "EnableTracking": true,
      "EnableClickTracking": true
    }
  }
}

// Program.cs
using Noundry.Sanquhar.Extensions;
using Noundry.Sanquhar.Mailgun.Extensions;

builder.Services.AddSanquhar(
    builder.Configuration,
    options => options.UseMailgun(builder.Configuration)
);

Usage Examples

See how easy it is to send emails with Sanquhar.

Send from Template

public class EmailService
{
    private readonly IMailService _mailService;

    public EmailService(IMailService mailService)
    {
        _mailService = mailService;
    }

    public async Task SendWelcome(
        string email,
        string name)
    {
        var model = new WelcomeModel
        {
            Name = name,
            Date = DateTime.Now
        };

        await _mailService.SendFromTemplateAsync(
            "Welcome", model, email);
    }
}

With Attachments

var message = await _mailService
    .CreateFromTemplateAsync(
        "Invoice", model);

message.To.Add(customer.Email);
message.Cc.Add("manager@company.com");

// Add attachment
message.Attachments.Add(new MailAttachment
{
    FileName = "invoice.pdf",
    Content = pdfBytes,
    ContentType = "application/pdf"
});

// Set priority
message.Priority = MailPriority.High;

await _mailService.SendAsync(message);

Modern .NET 9 Features

Built with the latest C# 13 and .NET 9 features for maximum performance and developer experience.

Collection Expressions

Modern C# 13 syntax with []

IHttpClientFactory

Proper HTTP client management

Source-Generated Regex

Compile-time regex generation