Carneiro.Core.Emails
7.6.2
dotnet add package Carneiro.Core.Emails --version 7.6.2
NuGet\Install-Package Carneiro.Core.Emails -Version 7.6.2
<PackageReference Include="Carneiro.Core.Emails" Version="7.6.2" />
<PackageVersion Include="Carneiro.Core.Emails" Version="7.6.2" />
<PackageReference Include="Carneiro.Core.Emails" />
paket add Carneiro.Core.Emails --version 7.6.2
#r "nuget: Carneiro.Core.Emails, 7.6.2"
#:package Carneiro.Core.Emails@7.6.2
#addin nuget:?package=Carneiro.Core.Emails&version=7.6.2
#tool nuget:?package=Carneiro.Core.Emails&version=7.6.2
Carneiro.Core.Emails
A transport-agnostic email sending abstraction (IEmailSender), with an SMTP implementation (SmtpEmailSender) built on MailKit.
Registration
services.AddSmtpEmailSender(configuration);
Overloads also accept an IConfigurationSection, an Action<SmtpEmailSenderOptions>, or a SmtpEmailSenderOptions instance directly. The IConfiguration overload reads from a section named SmtpEmailSenderOptions (nameof(SmtpEmailSenderOptions)).
Registration wires up IEmailSender → SmtpEmailSender (scoped).
IEmailSender
Exposes a single method, SendAsync(EmailMessage message, CancellationToken cancellationToken = default).
Implementations are expected to:
- Use
EmailMessage.Fromwhen set, otherwise fall back to a sender configured on the implementation itself (e.g.SmtpEmailSenderOptions.DefaultFrom). - Throw an implementation-specific exception derived from
EmailRzExceptionwhen the message can't be delivered.
SmtpEmailSender
- Connects to the configured SMTP server, optionally authenticates, sends the message, and always disconnects — even on failure.
- Wraps any exception raised while connecting, authenticating, or sending into an
EmailSendRzException, logging the failure beforehand. - Throws
InvalidOperationExceptionif the message has noFromand noSmtpEmailSenderOptions.DefaultFromis configured.
SmtpEmailSenderOptions
Settings below are listed by their configuration key, as read from the SmtpEmailSenderOptions section (e.g. an Octopus Deploy structured configuration variable):
SmtpEmailSenderOptions:Host(string) — the SMTP server host name.SmtpEmailSenderOptions:Port(int) — the SMTP server port. Defaults to587.SmtpEmailSenderOptions:SecureSocketOptions(MailKit.Security.SecureSocketOptions) — how the connection is secured. Defaults toStartTlsWhenAvailable.SmtpEmailSenderOptions:Username/SmtpEmailSenderOptions:Password(string?) — credentials used to authenticate. WhenUsernameis null or empty, no authentication is attempted.SmtpEmailSenderOptions:DefaultFrom:Address/SmtpEmailSenderOptions:DefaultFrom:DisplayName(EmailAddress?) — the sender address used when a message doesn't setEmailMessage.From.SmtpEmailSenderOptions:Timeout(TimeSpan) — connection and send timeout. Defaults to 30 seconds.
Models
EmailMessage—From,To,Cc,Bcc,ReplyTo(allEmailAddress),Subject,Body,IsBodyHtml(defaults totrue), andAttachments.EmailAddress— anAddresswith an optionalDisplayName; implicitly convertible from a plainstring, e.g.message.To.Add("jane.doe@example.com").EmailAttachment—FileName,Content(byte[]), andContentType(defaults toapplication/octet-stream).
Exceptions
EmailRzException— abstract base for all email-related exceptions.EmailSendRzException— thrown bySmtpEmailSenderwhen a message fails to send; wraps the underlying MailKit exception.
Example
var message = new EmailMessage
{
To = { "jane.doe@example.com" },
Subject = "Welcome!",
Body = "<p>Thanks for signing up.</p>",
};
await emailSender.SendAsync(message);
| 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
- Carneiro.Core.Exceptions (>= 7.6.2)
- MailKit (>= 4.18.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.