GaEpd.EmailService
1.1.1
Prefix Reserved
See the version list below for details.
dotnet add package GaEpd.EmailService --version 1.1.1
NuGet\Install-Package GaEpd.EmailService -Version 1.1.1
paket add GaEpd.EmailService --version 1.1.1
#r "nuget: GaEpd.EmailService, 1.1.1"
#:package GaEpd.EmailService@1.1.1
#addin nuget:?package=GaEpd.EmailService&version=1.1.1
#tool nuget:?package=GaEpd.EmailService&version=1.1.1
Georgia EPD-IT Email Service Library
This library was created by Georgia EPD-IT to provide common email services for our web applications.
Installation
To install, search for "GaEpd.EmailService" in the NuGet package manager or run the following command:
dotnet add package GaEpd.EmailService
Usage
The IEmailService interface provides a single method, SendEmailAsync(Message message), which sends an email
Message. Typical usage would look like this:
// Create the email message.
var message = Message.Create(subject, recipientEmail, textBody, htmlBody, senderName, senderEmail, [ccRecipient]);
// Send the message. There is no need to await this call.
_ = emailService.SendEmailAsync(message, token);
// Optionally log the message. This requires implementing the IEmailLogRepository interface.
await emailLogRepository.InsertAsync(message, token).ConfigureAwait(false);
Configuration
The AddEmailService() extension method can be used to register the included implementation with your configuration
settings. The DefaultEmailService implementation uses MailKit to send emails.
builder.Services.AddEmailService(builder.Configuration);
The following configuration section should be added to your configuration file:
{
"EmailServiceSettings": {
"EnableEmail": true,
"SmtpHost": "localhost",
"SmtpPort": 25,
"SecureSocketOption": "Auto",
"DefaultSenderName": "Default Sender",
"DefaultSenderEmail": "Default.Sender@email.invalid",
"EnableEmailAuditing": true,
"AuditEmailRecipients": [
"Audit.Recipient@email.invalid"
],
"EnableEmailLog": false
}
}
EnableEmail: Set totrueto enable sending emails.SmtpHost: The SMTP server to use for sending emails. (Only used ifEnableEmailistrue.)SmtpPort: The port to use for the SMTP server. (Only used ifEnableEmailistrue.)SecureSocketOption: The MailKitSecureSocketOptionto use for the SMTP server. (Only used ifEnableEmailistrue.) Available options areNone,Auto,SslOnConnect,StartTls, andStartTlsWhenAvailable. See the MailKit documentation for a description of each option.DefaultSenderName: The default sender name (optional, can also be set per message).DefaultSenderEmail: The default sender email address (optional, can also be set per message).EnableEmailAuditing: Set totrueto enable sending audit emails (useful for testing purposes).AuditEmailRecipients: A list of email addresses to send audit emails to. (Only used ifEnableEmailAuditingistrue.)EnableEmailLog: Not used by theDefaultEmailService. This is here as a convenience if you decide to implement and useIEmailLogRepository(see below). Set totrueto enable saving emails.
Note that EnableEmail, EnableEmailAuditing, and EnableEmailLog operate independently of each other. You can enable
or disable each feature individually.
Email Log Repository
The IEmailLogRepository interface provides a single method, InsertAsync(Message message), for logging each
email. No implementation is provided by default, so if you want to enable email logging, you will need to create
your own implementation and register it with the dependency injection container. The EnableEmailLog configuration
setting is available if desired to enable or disable email logging. The EmailLog class is also available for use as a database entity if desired.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- MailKitLite (>= 4.12.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.5)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.5)
-
net9.0
- MailKitLite (>= 4.12.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.5)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.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.
# Changelog
## [1.1.1] - 2025-06-02
- Fixed: Audit emails were formatted incorrectly for emails with no HTML body.
## [1.1.0] - 2025-01-28
- Target .NET 8 & 9.
- Fixed: Email sender was truncated more than required when saving to the repository.
## [1.0.0] - 2024-12-04
_Initial release._
[1.1.1]: https://github.com/gaepdit/email-service/releases/tag/v1.1.1
[1.1.0]: https://github.com/gaepdit/email-service/releases/tag/v1.1.0
[1.0.0]: https://github.com/gaepdit/email-service/releases/tag/v1.0.0
