This library provides an easy to use implementation of SMTP based email delivery using the MailKit library internally. This abstraction with proper interfaces allows email implementation inside of your project with little effort and easy to manage integration.
This package depends on the ICG.NetCore.Utilities.Email project for template implementation, as well as the IEmailService interface for Dependency Injection
The following additional NuGet packages are installed with this extension.
- MailKit - For email delivery
- ICG NET Core Utilities Email - For Email Template Configuration
In an effort to standardize our Email libraries a common IEmailService
interface was introduced, at this time the existing ISmtpService
was removed.
Standard installation via HuGet Package Manager
Install-Package ICG.NetCore.Utilities.Email.Smtp
To setup the needed dependency injection items for this library, add the following line in your DI setup.
services.UseIcgNetCoreUtilitiesEmailSmtp(configuration);
Additionally you must specify the needed configuration elements within your AppSettings.json file
"SmtpServiceOptions": {
"AdminEmail": "test@test.com",
"AdminName" : "John Smith",
"Server": "test.smtp.com",
"Port": 527,
"UseSsl": true,
"SenderUsername": "MySender",
"SenderPassword": "Password",
"AlwaysTemplateEmails": true,
"AddEnvironmentSuffix": true
},
"EmailTemplateSettings": {
"DefaultTemplatePath": "Template.html",
"AdditionalTemplates": { "SpecialTemplate": "File.html" }
}
Setting | Description |
---|---|
AdminEmail | This is the email address used as the "from" address and also for any usage of the "SendToAdministrator" option |
AdminName | This is the optional name for the sender for all outbound messages |
Server | The SMTP Server address to use |
Port | The Port to use for outbound emails |
UseSsl | Should SSL be used for emails |
SenderUsername | The username that should be used to connect to SMTP |
SenderPassword | The password that should be used to connect to SMTP |
AlwaysTemplateEmails | If selected ALL emails sent will be templated, by default using the "DefaultTemplate" as configured |
AddEnvironmentSuffix | If selected, all outbound emails sent from non-production addresses will have the environment name added to the end of the subject |
DefaultTemplatePath | The path, relative to the application root, where the default HTML template can be found for emails |
AdditionalTemplates | These are name/value pairs of additional templates and totally optional |
Usage is primarly completed by injecting the IEmailService
interface to your respective project, one injected emails can be sent with a single line of code.
_service.SendEmail("recipient@me.com", "My Subject", "<p>Hello!</p>");
Inline documentation exists for all API methods. We will continue to add more to this documentation in the future (PR's Welcome)
ICG has a number of other related projects as well