MH.EmailService 2.0.3

dotnet add package MH.EmailService --version 2.0.3
                    
NuGet\Install-Package MH.EmailService -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MH.EmailService" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MH.EmailService" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MH.EmailService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MH.EmailService --version 2.0.3
                    
#r "nuget: MH.EmailService, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MH.EmailService&version=2.0.3
                    
Install MH.EmailService as a Cake Addin
#tool nuget:?package=MH.EmailService&version=2.0.3
                    
Install MH.EmailService as a Cake Tool

EmailService

A lightweight .NET 8 library for sending emails via SMTP, designed for seamless integration with ASP.NET Core applications.

Features

  • Simple and intuitive API for sending emails
  • Supports SMTP configuration via appsettings.json
  • Built-in dependency injection support
  • Clean separation of concerns using IEmailService interface
  • Fully configurable via EmailSettings

Installation

Install the package via NuGet Package Manager:

dotnet add package MH.EmailService

Configuration

Add the following section to your appsettings.json:

For using SMTP

"SmtpSettings": {
  "From": "your-email@example.com",
  "AppPassword": "your-app-password",
  "Host": "smtp.example.com",
  "Port": 587
}

For using SendGrid

"SendGridSettings": {
    "ApiKey": "your-sendgrid-api-key",
    "From": "your-email",
    "FromName": "your-name",
  }

Usage

1. Register the EmailService

In your Program.cs or Startup.cs, register the service:

builder.Services.AddSmtpService(builder.Configuration); // For SMTP
// or
builder.Services.AddSendGridEmailService(builder.Configuration); // For SendGrid

2. Inject and Use IEmailService

In your classes or controllers, inject ISmtpService or ISendGridService and use it to send emails:

public class NotificationService
{
    private readonly ISmtpService _smtpService;
    private readonly ISendGridService _sendGridService;

    public NotificationService(ISmtpService smtpService, ISendGridService sendGridService)
    {
        _smtpService = smtpService;
        _sendGridService = sendGridService;
    }

    public async Task SendNotification(string to, string subject, string body)
    {
        var emailDto = new SendEmailDto
        {
            To = to,
            Subject = subject,
            Body = body
        };

        // For SMTP
        await _smtpService.SendEmailAsync(emailDto);

        // For SendGrid
        await _sendGridService.SendEmailAsync(emailDto);
    }
}

API Reference

SendEmailDto

Property Type Description
To string Recipient email address
Subject string Email subject
Body string Email body content

SmtpSettings

Property Type Description
From string Sender email address
AppPassword string SMTP app password or token
Host string SMTP server host
Port int SMTP server port (e.g., 587)

SendGridSettings

Property Type Description
ApiKey string SendGrid API key
From string Sender email address
FromName string Sender name

Authors

  • Mohammad
  • Heba

License

This project is licensed under the MIT License. See the LICENSE file for details.

Repository

For more information, visit the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 208 5/14/2025
1.0.0 116 5/11/2025