Mitc.Email.Abstractions 1.2.0

Mitc.Email.Abstractions

Abstractions and default implementation for sending email in MITC applications. Provides a MailService that routes outbound email through a pluggable IMailTransport, with configurable recipient filtering and service modes.

Features

  • Service modesSendAll, SendWithRestrictions, or DenyAllOutbound to control whether email leaves the system.
  • Recipient filtering — optional rules that match recipients by exact address or regular expression.
  • Attachments — send file attachments, including inline images referenced by content ID.
  • Options validationMailSettingsValidator validates configuration at startup via IValidateOptions<MailSettings>.
  • Transport abstraction — implement IMailTransport to plug in any email provider (SMTP, SendGrid, etc.).

Configuration

Add MailSettings to your configuration (e.g. appsettings.json):

{
  "MailSettings": {
    "ServiceMode": "SendWithRestrictions",
    "FromAddress": "no-reply@example.com",
    "RecipientFilterRules": [
      { "AddressType": "Literal", "RecipientAddress": "allowed@example.com" },
      { "AddressType": "RegEx", "RecipientAddress": "@example\\.com$" }
    ]
  }
}

Registration

AddMitcMailSettings binds and validates MailSettings and registers the RecipientEvaluator that MailService depends on:

builder.AddMitcMailSettings();
builder.Services.AddScoped<IMailTransport, MySmtpTransport>(); // your implementation
builder.Services.AddScoped<MailService>();

Usage

await mailService.SendAsync(new SendEmailRequest(
    address: "user@example.com",
    subject: "Welcome",
    body: "<p>Hello!</p>"
));

The body is sent as HTML by default. Pass bodyFormat: BodyFormat.PlainText for a plain-text body:

await mailService.SendAsync(new SendEmailRequest(
    address: "user@example.com",
    subject: "Welcome",
    body: "Hello!",
    bodyFormat: BodyFormat.PlainText
));

Attachments

Pass an EmailAttachment for each file. Supplying a contentId marks the attachment for inline display, letting you reference it from the HTML body via cid::

var pdf = await File.ReadAllBytesAsync("invoice.pdf");
var logo = await File.ReadAllBytesAsync("logo.png");

await mailService.SendAsync(new SendEmailRequest(
    address: "user@example.com",
    subject: "Your invoice",
    body: "<p>See attached.</p><img src=\"cid:logo\">",
    attachments: new[]
    {
        new EmailAttachment(pdf, "application/pdf", "invoice.pdf"),
        new EmailAttachment(logo, "image/png", "logo.png", contentId: "logo"),
    }));

Showing the top 20 packages that depend on Mitc.Email.Abstractions.

Packages Downloads
Mitc.Email.AzureCommunication
Azure Communication Services implementation of IMailTransport for Mitc.Email.Abstractions.
0
Mitc.Email.SendGrid
SendGrid implementation of IMailTransport for Mitc.Email.Abstractions.
1
Mitc.Email.SendGrid
SendGrid implementation of IMailTransport for Mitc.Email.Abstractions.
144
Mitc.Email.SendGrid
SendGrid implementation of IMailTransport for Mitc.Email.Abstractions.
152
Mitc.Email.Templating
Blazor-based email templating service with strongly-typed models and integrated sending via Mitc.Email.Abstractions.
0
Mitc.Email.Templating
Blazor-based email templating service with strongly-typed models and integrated sending via Mitc.Email.Abstractions.
144
Mitc.Email.Templating
Blazor-based email templating service with strongly-typed models and integrated sending via Mitc.Email.Abstractions.
152

.NET 10.0

  • No dependencies.

.NET 5.0

.NET 6.0

.NET 7.0

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
1.4.0 0 7/14/2026
1.3.0 152 7/13/2026
1.2.0 152 7/10/2026
1.1.0 1 7/9/2026
1.0.0 144 2/20/2026