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 modes —
SendAll,SendWithRestrictions, orDenyAllOutboundto 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 validation —
MailSettingsValidatorvalidates configuration at startup viaIValidateOptions<MailSettings>. - Transport abstraction — implement
IMailTransportto 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
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0 && < 6.0.0)
- Microsoft.Extensions.Options (>= 5.0.0 && < 6.0.0)
.NET 6.0
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.Options (>= 6.0.0 && < 7.0.0)
.NET 7.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0 && < 8.0.0)
- Microsoft.Extensions.Options (>= 7.0.0 && < 8.0.0)
.NET 8.0
- No dependencies.
.NET 9.0
- No dependencies.
.NET Standard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0 && < 4.0.0)
- Microsoft.Extensions.Options (>= 3.1.0 && < 4.0.0)