Lyo.Email.Postgres 2.0.1

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

Lyo.Email.Postgres

PostgreSQL EF Core store for email mailbox logs (EmailLogEntity / EmailAttachmentLogEntity). The package never sends or fetches mail. It wires EmailDbContext so workers or gateways can persist send and receive outcomes after Lyo.Email (outbound) or a host IMAP/POP client (inbound). There is no FileStorage id on the schema; hosts that save HTML write their own file and record the path.

Features

  • Schema only. email.email_logs and email.email_attachment_logs. This package does not send SMTP, fetch IMAP/POP, or subscribe to EmailService events.
  • Direction. EmailDirection.Outbound (default) or Inbound, matching SMS mailbox logs.
  • Bodies. Plain text on the row (TextBody). HTML is a host-owned file whose name and path are stored (HtmlFileName / HtmlFilePath), not a FileStorage id.
  • Attachments. Metadata only: file name, content type, byte length, optional JSON bag, sort order. Bytes are not stored.
  • DI. AddEmailDbContext / AddEmailDbContextFactory / AddEmailDbContextFactoryFromConfiguration.

Examples

Injection helpers

services.AddEmailDbContextFactoryFromConfiguration(builder.Configuration);
// or
services.AddEmailDbContextFactory(opts =>
{
    opts.ConnectionString = "Host=...;Database=...;Username=...;Password=...";
    opts.EnableAutoMigrations = true;
});

Insert after send

emailService.EmailSent += async (_, args) =>
{
    var result = args.EmailResult;
    var request = result.Data;
    string? htmlFileName = null;
    string? htmlFilePath = null;
    if (!string.IsNullOrWhiteSpace(request?.HtmlBody))
    {
        htmlFileName = $"{Guid.NewGuid():N}.html";
        htmlFilePath = Path.Combine(htmlArchiveRoot, htmlFileName);
        await File.WriteAllTextAsync(htmlFilePath, request.HtmlBody);
    }

    await using var context = await factory.CreateDbContextAsync();
    context.EmailLogs.Add(new EmailLogEntity
    {
        Direction = EmailDirection.Outbound,
        FromAddress = request?.FromAddress,
        Subject = request?.Subject,
        TextBody = request?.TextBody,
        HtmlFileName = htmlFileName,
        HtmlFilePath = htmlFilePath,
        IsSuccess = result.IsSuccess,
        Message = result.SmtpResponse,
        MessageId = result.MessageId,
        SentTimestamp = result.SentDate,
        ErrorMessage = result.Errors?.FirstOrDefault()?.Message
    });
    await context.SaveChangesAsync();
};

Types

  • EmailDbContext. EF Core context exposing DbSet<EmailLogEntity> (email_logs) and DbSet<EmailAttachmentLogEntity> (email_attachment_logs). Default schema is email. SaveChanges and SaveChangesAsync stamp CreatedTimestamp on insert and UpdatedTimestamp on update for both entities.
  • EmailDbContextFactory. Design-time factory for EF Core tools.
  • EmailDirection. Outbound (default) or Inbound.
  • EmailLogEntity. Direction, sender, recipients (jsonb), subject, TextBody, host-owned HtmlFileName / HtmlFilePath, success flag, SMTP or fetch note, error message, MIME MessageId, SentTimestamp / ReceivedTimestamp, and audit timestamps. Attachment bytes and HTML content are not stored on this row.
  • EmailAttachmentLogEntity. Attachment metadata only (file name, ContentType, SizeBytes, MetadataJson, SortOrder) linked back to an EmailLogEntity. No FileStorage id.
  • PostgresEmailOptions. An IPostgresMigrationConfig implementation. Section name is PostgresEmail. Default schema is email. EnableAutoMigrations defaults to false.

Injection helpers

Every extension hangs off IServiceCollection. Hosts map and insert; this package does not subscribe to send events.

Extension Description
AddEmailDbContext(string connectionString) Wires an IDbContextFactory<EmailDbContext> plus a scoped EmailDbContext taken from the factory.
AddEmailDbContextFactory(PostgresEmailOptions options) Registers IDbContextFactory<EmailDbContext> against options.ConnectionString with the email migrations history schema, plus support for the Lyo.Postgres migration runner.
AddEmailDbContextFactory(Action<PostgresEmailOptions> configure) Same as above, using an inline configuration callback.
AddEmailDbContextFactoryFromConfiguration(IConfiguration configuration, string configSectionName = PostgresEmailOptions.SectionName) Reads PostgresEmailOptions from configuration (section defaults to PostgresEmail) and wires the factory.

Supported frameworks

net10.0

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Exceptions (direct, lyo)
  • Lyo.Postgres (direct, lyo)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 (direct, microsoft)
  • Lyo.Health (transitive, lyo)
  • Microsoft.EntityFrameworkCore 10.0.5 (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Options 10.0.5 (transitive, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 (transitive, third-party)
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

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
2.0.1 81 9/14/2026
2.0.0 96 9/9/2026
1.0.13 102 8/25/2026
1.0.11 103 8/23/2026
1.0.9 103 8/22/2026
1.0.6 102 8/20/2026
1.0.4 107 8/20/2026
1.0.3 99 8/19/2026
1.0.2 104 8/19/2026
1.0.1 104 8/18/2026
1.0.0 109 8/16/2026