CodeLogic.Mail
4.5.2-preview.68
See the version list below for details.
dotnet add package CodeLogic.Mail --version 4.5.2-preview.68
NuGet\Install-Package CodeLogic.Mail -Version 4.5.2-preview.68
<PackageReference Include="CodeLogic.Mail" Version="4.5.2-preview.68" />
<PackageVersion Include="CodeLogic.Mail" Version="4.5.2-preview.68" />
<PackageReference Include="CodeLogic.Mail" />
paket add CodeLogic.Mail --version 4.5.2-preview.68
#r "nuget: CodeLogic.Mail, 4.5.2-preview.68"
#:package CodeLogic.Mail@4.5.2-preview.68
#addin nuget:?package=CodeLogic.Mail&version=4.5.2-preview.68&prerelease
#tool nuget:?package=CodeLogic.Mail&version=4.5.2-preview.68&prerelease
CodeLogic.Mail
SMTP/IMAP e-mail library for CodeLogic with a built-in variable-substitution template engine (variables, conditionals, loops, and layouts), attachment support, and full IMAP mailbox management including RFC 2177 IDLE push notifications. Built on MailKit.
Install
dotnet add package CodeLogic.Mail
Quick Start
using CL.Mail;
await Libraries.LoadAsync<MailLibrary>();
var mail = Libraries.Get<MailLibrary>()!;
// Compose with the fluent builder and send via SMTP.
var message = mail.CreateMessage()
.From("noreply@example.com", "My App")
.To("user@example.com")
.Subject("Welcome!")
.HtmlBody("<h1>Hello</h1><p>Welcome aboard.</p>")
.TextBody("Hello — welcome aboard.")
.Build();
MailResult result = await mail.Smtp.SendAsync(message);
if (!result.IsSuccess)
Console.WriteLine($"Send failed ({result.Error}): {result.ErrorMessage}");
Features
- SMTP sending — plain-text and/or HTML bodies, CC/BCC, attachments, custom headers, message priority. A fresh connection is opened per send (no pooling).
- Fluent
MailBuilder— compose immutableMailMessageobjects with validation. - Template engine — JSON-backed templates with
{{var}},${var}, and{var}substitution,{{#if}}…{{#else}}…{{/if}}conditionals,{{#each}}…{{/each}}loops, and{{#section}}/ layout composition. - Templated send —
SendTemplatedAsyncrenders a template by ID and sends in one call. - IMAP reading — list folders, fetch/page messages, fetch by UID with attachments, search, move/copy/delete, and add/remove flags.
- IMAP IDLE — RFC 2177 push notifications via
StartIdleAsyncand theNewMailReceivedevent. - Result-based errors — operations return
MailResult/MailResult<T>with a categorisedMailErrorinstead of throwing. - Health checks — reports SMTP/IMAP configuration status.
Configuration
Registered under the mail section (serialized to
config.mail.json in the library's config directory):
{
"Enabled": true,
"Smtp": {
"Host": "smtp.example.com",
"Port": 587,
"Username": "noreply@example.com",
"Password": "your-password-or-app-password",
"SecurityMode": "StartTls",
"TimeoutSeconds": 30
},
"Imap": {
"Host": "imap.example.com",
"Port": 993,
"Username": "inbox@example.com",
"Password": "your-password-or-app-password",
"SecurityMode": "SslTls",
"TimeoutSeconds": 30,
"EnableIdle": false,
"IdleRefreshMinutes": 25
},
"DefaultFromEmail": "noreply@example.com",
"DefaultFromName": "My App",
"TemplateDirectory": "templates"
}
SecurityModeis one ofNone,StartTls, orSslTls.- The whole
Imapsection is optional — omit it to disable IMAP entirely. TemplateDirectoryis resolved relative to the library's data directory unless an absolute path is given; it defaults to atemplatessubfolder.
Documentation
Requirements
- CodeLogic 3.x or 4.x | .NET 10
License
MIT — see LICENSE
| Product | Versions 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. |
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 |
|---|---|---|
| 4.6.72 | 198 | 6/20/2026 |
| 4.6.69-preview | 39 | 6/20/2026 |
| 4.5.2 | 106 | 5/24/2026 |
| 4.5.2-preview.68 | 60 | 6/20/2026 |
| 4.5.1 | 158 | 5/24/2026 |
| 4.5.1-preview.56 | 89 | 5/24/2026 |
| 4.4.2-preview.53 | 58 | 5/24/2026 |
| 4.4.1 | 105 | 5/24/2026 |
| 4.0.5 | 102 | 5/15/2026 |
| 4.0.4 | 110 | 5/9/2026 |
| 4.0.3 | 114 | 5/9/2026 |
| 3.3.1 | 619 | 4/18/2026 |
| 3.3.0 | 117 | 4/18/2026 |
| 3.2.11 | 119 | 4/18/2026 |
| 3.2.10 | 117 | 4/18/2026 |
| 3.2.9 | 110 | 4/18/2026 |
| 3.2.8 | 104 | 4/18/2026 |
| 3.2.7 | 104 | 4/18/2026 |
| 3.2.6 | 109 | 4/18/2026 |
| 3.2.5 | 106 | 4/18/2026 |
# CL.Mail — Changelog
All notable changes to **CodeLogic.Mail** are documented here. Versions follow
[Semantic Versioning](https://semver.org/).
## [4.5.1] — 2026-06-20
### Documentation
- Rewrote the README and the Mail & Templates guide to match the current public
API. The previous docs described members that no longer exist (`EmailMessage`,
`EmailAttachment`, `ReplyTo`, `RenderTemplateAsync`, `ReadInboxAsync`,
`ImapFilter`, `MarkAsReadAsync`, the `SendAsync(from:, to:, …)` /
`SendTemplateAsync` overloads, and the `UseSsl` / `FromAddress` config keys).
- Documented the real surface: the fluent `MailBuilder` (`CreateMessage()`),
`SmtpService.SendAsync(MailMessage)`, `MailLibrary.SendTemplatedAsync`, the
`MailResult` / `MailError` result model, and the JSON-backed template system
(`MailTemplate`, `IMailTemplateProvider`, `IMailTemplateEngine`).
- Documented previously undocumented features: template conditionals
(`{{#if}}`/`{{#else}}`), loops (`{{#each}}`), sections and layouts; the
`${var}` / `{var}` placeholder syntaxes; the full IMAP API (fetch/page, fetch
by UID, search via `ImapSearchCriteria`, move/copy/delete, flag operations,
folder management); and RFC 2177 IMAP IDLE push (`StartIdleAsync` /
`NewMailReceived`) with its `EnableIdle` / `IdleRefreshMinutes` config keys.
- Corrected the documented config schema and `SecurityMode` values
(`None` / `StartTls` / `SslTls`).
## [4.5.0] — 2026-05-24
### Changed
- **Unified versioning.** All CodeLogic.Libs now share a single version line
controlled by `version.txt` in the repo root. This is a version alignment
release — no functional changes to this library.
## [4.0.4] — 2026-04-16
### Changed
- README + manifest refresh for the v4 baseline. No functional changes vs 4.0.3.
- `LibraryManifest.Version` now reads from assembly metadata.
## [4.0.2] — 2026-04-09
### Changed
- Annotated mail configuration with `[ConfigField]` for the admin UI surface.
- Aligned with the v4 baseline across all libraries.
### Fixed
- Resolved null-reference warnings in `ImapService`.
## [4.0.0] — 2026-04-09
Major rewrite. Republished as v4.0.0 to reset the version line under the
unified v4 baseline. SMTP / IMAP services + a CodeLogic-native template
provider.
### Notes
- Earlier history is retained in the
[git log](https://github.com/Media2A/CodeLogic.Libs/commits/main/CL.Mail).