CaseTunisia.Tools.MailService 1.1.1

CaseTunisia.Tools.MailService

This is as EMail service tool aim to ease sending emails using smtp clients, to use it is pretty simple all you need to do is

  • Initialize AuthMessageSenderOptions configuration which is used to preset the email service configuration:
    services.Configure<AuthMessageSenderOptions>(Configuration.GetSection("AuthMessageSenderOptions"));

and for sure don't forget to add AuthMessageSenderOptions to your appsettings.json file, and here is an example of that:

    "AuthMessageSenderOptions": {
        "Domain": "smtp.sendgrid.net",
        "Port": "587",
        "UserName": "myusername",
        "Key": "mykey",
        "UseSsl": "false",
        "DefaultSenderEmail": "support@Auerswald.de",
        "DefaultSenderDisplayName": "Identity server",
        "UseHtml": "true"
    }
  • Add a singleton middleware to your app service like:
    services.AddSingleton<IEmailSender, EmailSender>();
  • Initialize your EmailSender interface and you are right to go:
using CaseTunisia.Tools.MailService;
...
    private readonly IEmailSender _emailSender;
    
    public AccountController(..., IEmailSender emailSender, ...)
    {
        ...
        _emailSender = emailSender;
        ...
    }

to simplify the usage, it is a good practice to create an EmailSenderExtensions.cs class like:

    public static class EmailSenderExtensions
    {
        public static Task SendEmailConfirmationAsync(this IEmailSender emailSender, string email, string link)
        {
            return emailSender.SendEmailAsync(email, "Confirm your email",
                $"Please confirm your account by clicking this link: <a href='{HtmlEncoder.Default.Encode(link)}'>link</a>");
        }
    }

and then in your controller you wil have only to call the EmailSenderExtensions methods over your IEmailSender interface;

    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

this is just an example of use.

No packages depend on CaseTunisia.Tools.MailService.

.NET Standard 2.1

Version Downloads Last updated
1.2.0 939 10/07/2023
1.1.1 429 11/20/2022