NeoMailing 1.0.4

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

NeoMailing

NeoMailing is a lightweight .NET library for sending emails via SMTP with optional HTML templating powered by Scriban.

It provides a clean abstraction (IEmailSender) and a flexible SMTP implementation (SmtpEmailSender) that supports:

  • Plain text, HTML, or both (multipart/alternative).
  • CC, BCC, Reply-To, and attachments.
  • Authentication modes: Basic (username/password), OAuth2, or None.
  • Integration with ASP.NET Core DI or manual instantiation.
  • Fast and reusable HTML templating with Scriban and caching.

✨ Features

  • 📧 Send plain text, HTML, or both in the same message.
  • 👥 Multiple recipients, CCs, BCCs, and Reply-To support.
  • 📎 File attachments with proper MIME type handling.
  • 🔑 Authentication: Basic, OAuth2 (e.g. Gmail, Office365), or no-auth for local dev servers.
  • 🧩 Integrates easily with IServiceCollection or can be instantiated manually.
  • 🎨 HTML templating via Scriban with caching and case-insensitive rendering.

🚦 When to Use

Best suited for:

  • Applications that need to send notifications, onboarding emails, password resets, or transactional reports.
  • Systems where SMTP configuration varies by environment (dev/staging/prod).

⚠️ Not suited for:

  • High-volume mailing (consider Mailgun, SendGrid, Amazon SES for bulk).
  • Tracking analytics, bounce handling, or campaign management.

📦 Installation

From NuGet:

dotnet add package NeoMailing

Or reference locally in your solution:

<ProjectReference Include="..\NeoMailing\NeoMailing.csproj" />

🚀 Usage

Manual Instantiation

using NeoMailing;

var settings = new SmtpSettings
{
    Host = "smtp.gmail.com",
    Port = 587,
    AuthMode = SmtpAuthMode.Basic,
    UseStartTls = true,
    Username = "myusername@gmail.com",
    Password = "mypassword"
};

var emailSender = new SmtpEmailSender(
    Microsoft.Extensions.Options.Options.Create(settings)
);

// Send simple HTML email
await emailSender.SendHtmlAsync(
    fromName: "NeoClinic",
    fromAddress: "noreply@neoclinic.com",
    toAddresses: new[] { "user@example.com" },
    subject: "Welcome!",
    htmlBody: "<h1>Hello</h1><p>Thanks for joining NeoClinic!</p>"
);

With Dependency Injection (ASP.NET Core)

// Program.cs
builder.Services.AddMailing(builder.Configuration, "Smtp");

// appsettings.json
"Smtp": {
  "Host": "smtp.gmail.com",
  "Port": 587,
  "UseStartTls": true,
  "AuthMode": "Basic",
  "Username": "myusername@gmail.com",
  "Password": "mypassword"
}

Injected usage:

public class MailService
{
    private readonly IEmailSender _email;

    public MailService(IEmailSender email) => _email = email;

    public async Task SendOtpAsync(string toEmail, string otp, CancellationToken ct)
    {
        await _email.SendTextAsync(
            "NeoClinic",
            "noreply@neoclinic.com",
            new[] { toEmail },
            "Your OTP Code",
            $"Your one-time code is: {otp}",
            ct
        );
    }
}

With Attachments

await emailSender.SendWithAttachmentsAsync(
    "NeoClinic Reports",
    "reports@neoclinic.com",
    new[] { "user@example.com" },
    "Monthly Report",
    htmlBody: "<p>See attached report.</p>",
    textBody: "See attached report.",
    attachments: new[]
    {
        ("report.pdf", File.ReadAllBytes("sample-files/report.pdf"), "application/pdf")
    }
);

🎨 Templating (Scriban)

NeoMailing includes TemplateRenderer to render Scriban templates with model binding and caching.

using NeoMailing;

var template = "<p>Hello {{ name }}!</p><p>Your OTP: {{ otp }}</p>";
var model = new { name = "John", otp = "123456" };

var html = TemplateRenderer.Render(template, model);

// Then pass into email
await emailSender.SendHtmlAsync("NeoClinic", "noreply@neoclinic.com",
    new[] { "user@example.com" },
    "OTP Verification",
    html);

Case-insensitive rendering:

TemplateRenderer.RenderCaseInsensitive("Hello {{ NAME }}", new { Name = "John" });
// -> "Hello John"

📝 Notes

  • Works with Gmail, Outlook/Office365, Yahoo, and custom SMTP servers.
  • For Gmail/Office365 OAuth2, you must first obtain an access token via their respective OAuth flows.
  • For dev environments, you can use local mail servers like MailHog or Papercut SMTP.
  • Emails are sent as multipart/alternative when both text and HTML bodies are provided, ensuring compatibility with all clients.

📖 License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.0.4 153 9/6/2025
1.0.3 122 9/6/2025