Email Sender

Represents a wrapper around the class SmtpClient. It provides an abstraction so you can interact with an SMTP client with a single method.

Definition

Namespace: Tipi.Tools.Email

Assembly: Tipi.Tools.Email.dll

Package: Tipi.Tools.EmailSender

This class lets you interact with the SmtpClient email sender.

Copied!

                
    SenderOptions options = new SenderOptions("PORT", "SERVER", "SSL", "USER", "PASSWORD", "EMALNAME");
    EmailSender = new EmailSender(options);
                
            
Dependency Injection

You can implement this class with a .Net Core app by injecting it on your Program.cs file.

Copied!

                
    using Tipi.Tools.Payments.Config;
    ...
    var builder = WebApplication.CreateBuilder(args);
    ...
    // Inject the Payment Processor
    // It is good practice to inject your keys from the Secrets.json
    builder.Services.ConfigureEmailSender("PORT", "SERVER", "SSL", "USER", "PASSWORD", "EMALNAME"); 
                
            
Controller Example

Here is an example of how to use the class in a controller, this can only be used if the class was configured during Dependency Injection.

Copied!

                
    using Tipi.Toolkit;
    ...
    public class  CheckoutController : Controller
    {
        // Define your private property
        private readonly IEmailSender _sender;
        ...
        public CheckoutController(IEmailSender sender)
        {
            _sender = sender;
        }
    }
                
            
Usage Example

Here is an example of the complete usage of the class.

Copied!

                
    // Send new email
     _sender.SendEmailAsync("UserEmail", "Subject", "Body");
                
            
Remarks

The EmailSender class is a wrapper to communicate with the SmtpClient email sender.

The class has a contructure that require you to pass six parameters, the server port, yor server, if use ssl, server user, password and sender name. This class can work with the .Net Framework Dependency Injection, by providing methods to work in that way. All of the Method calls can be awaited and are thread safe

Constructors

Create an instance of EmailSender class, takin as parameter a new object of type SenderOptions

Related Classes

Class used as parameter in order to initialize the EmailSender class.