This library was created by Georgia EPD-IT to provide common email services for our web applications.
To install, search for "GaEpd.EmailService" in the NuGet package manager or run the following command:
dotnet add package GaEpd.EmailService
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);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"
]
}
}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.)
Note that EnableEmail and EnableEmailAuditing operate independently of each other. You can enable or disable each
feature individually.
