Structr.Email package is intended to help sending email notifications.
Installation
Email package is available on NuGet.
Setup
Setup basic email service:
AddEmail()
extension method performs registration email service IEmailSender
. Additionally configure IEmailSender
service used EmailOptions
class. EmailOptions
properties:
From
EmailAddress
Email address of a sender. Required option, which configuring with AddEmail()
method.
TemplateRootPath
string?
Root directory path with email templates (needed if using email templates), default value is null
.
Email service uses different email clients. For example: File-client, SMTP-client, clients for cloud-based email delivery platform (like SendGrid, MailChimp etc.) or something else. You can use one of default implemented email client from list:
SMTP-client
An SMTP-client allows sending of email notifications using a SMTP server. Setup email service with SMTP-client:
Additionally configure SMTP-client used SmtpOptions
class. SmtpOptions
properties:
Host
string
Domain name or IP address (IPv4) of the host used for SMTP transactions. Required option, which configuring with AddSmtpClient()
method.
Port
int
Port used for SMTP transactions. Required option, which configuring with AddSmtpClient()
method, default value is 25
.
User
string?
User name used to authenticate a sender, default value is null
.
Password
string?
User password used to authenticate a sender, default value is null
.
IsSslEnabled
bool
Specify whether the SMTP-client uses SSL to encrypt a connection, default value is false
.
File-client
An File-client allows preserving of email notifications to file system. This behavior can be useful in development environment for example. Setup email service with File-client:
You also can use clients depending on the environment. For example you can use File-client for development environment and SMTP-client for production environment.
Usage
After setup you can inject IEmailSender
service and use it for sending email notifications:
Templates
You can use EmailTemplateMessage
, EmailTemplateFileMessage
classes to sending email notifications generating via templates. By default templates constructing via "{{" and "}}", for example "{{UserName}}".
Example of using dynamic template:
Example of using static template:
See example of using template file in Razor section.
Last updated