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
<PackageReference Include="Lyo.Email.Postgres" Version="2.0.1" />
<PackageVersion Include="Lyo.Email.Postgres" Version="2.0.1" />
<PackageReference Include="Lyo.Email.Postgres" />
paket add Lyo.Email.Postgres --version 2.0.1
#r "nuget: Lyo.Email.Postgres, 2.0.1"
#:package Lyo.Email.Postgres@2.0.1
#addin nuget:?package=Lyo.Email.Postgres&version=2.0.1
#tool nuget:?package=Lyo.Email.Postgres&version=2.0.1
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_logsandemail.email_attachment_logs. This package does not send SMTP, fetch IMAP/POP, or subscribe toEmailServiceevents. - Direction.
EmailDirection.Outbound(default) orInbound, 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 exposingDbSet<EmailLogEntity>(email_logs) andDbSet<EmailAttachmentLogEntity>(email_attachment_logs). Default schema isemail.SaveChangesandSaveChangesAsyncstampCreatedTimestampon insert andUpdatedTimestampon update for both entities.EmailDbContextFactory. Design-time factory for EF Core tools.EmailDirection.Outbound(default) orInbound.EmailLogEntity. Direction, sender, recipients (jsonb), subject,TextBody, host-ownedHtmlFileName/HtmlFilePath, success flag, SMTP or fetch note, error message, MIMEMessageId,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 anEmailLogEntity. No FileStorage id.PostgresEmailOptions. AnIPostgresMigrationConfigimplementation. Section name isPostgresEmail. Default schema isemail.EnableAutoMigrationsdefaults tofalse.
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.Design10.0.5(direct, microsoft)Lyo.Health(transitive, lyo)Microsoft.EntityFrameworkCore10.0.5(transitive, microsoft)Microsoft.EntityFrameworkCore.Relational10.0.5(transitive, microsoft)Microsoft.Extensions.Hosting.Abstractions10.0.5(transitive, microsoft)Microsoft.Extensions.Options10.0.5(transitive, microsoft)Npgsql.EntityFrameworkCore.PostgreSQL10.0.3(transitive, third-party)
| 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. |
-
net10.0
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Postgres (>= 2.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.