Moclawr.Services.External 2.1.0

dotnet add package Moclawr.Services.External --version 2.1.0
                    
NuGet\Install-Package Moclawr.Services.External -Version 2.1.0
                    
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="Moclawr.Services.External" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Moclawr.Services.External" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Moclawr.Services.External" />
                    
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 Moclawr.Services.External --version 2.1.0
                    
#r "nuget: Moclawr.Services.External, 2.1.0"
                    
#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.
#:package Moclawr.Services.External@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Moclawr.Services.External&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Moclawr.Services.External&version=2.1.0
                    
Install as a Cake Tool

Moclawr.Services.External

NuGet

Overview

The Moclawr.Services.External package provides implementations for integrating with external services such as SMTP for email sending and SMS gateways. It simplifies the process of configuring and using these external communication services in your .NET applications.

Features

  • SMTP Services: Comprehensive email sending capabilities with support for:

    • Single and multiple recipients
    • CC and BCC functionality
    • Email attachments
    • HTML and plain text email bodies
    • Configurable SMTP settings
  • SMS Services: Text message sending functionality with support for:

    • Single recipient messaging
    • Bulk messaging to multiple recipients
    • Configurable SMS gateway settings
  • Dependency Injection: Easy integration with ASP.NET Core applications through extension methods

Installation

Install the package via NuGet Package Manager:

dotnet add package Moclawr.Services.External

Usage

Configuration

Add the following configuration in your appsettings.json:

{
  "SmtpConfiguration": {
    "Server": "smtp.example.com",
    "Port": 587,
    "Username": "your-username",
    "Password": "your-password",
    "EnableSsl": true,
    "SenderEmail": "sender@example.com",
    "SenderName": "Your Sender Name"
  },
  "SmsConfiguration": {
    "ApiKey": "your-api-key",
    "ApiSecret": "your-api-secret",
    "SenderName": "YourCompany"
  }
}

Service Registration

Register the services in your Program.cs or Startup.cs:

using Services.External;

// Add SMTP services
services.AddSmtpService(Configuration);

// Add SMS services
services.AddSmsService(Configuration);

Sending Emails

using Services.External.SmtpService;

public class NotificationService
{
    private readonly ISmtpServices _smtpServices;

    public NotificationService(ISmtpServices smtpServices)
    {
        _smtpServices = smtpServices;
    }

    public void SendWelcomeEmail(string userEmail, string userName)
    {
        string subject = "Welcome to our platform!";
        string body = $"<h1>Hello {userName}!</h1><p>Welcome to our platform.</p>";
        
        _smtpServices.SendEmail(userEmail, subject, body, isHtml: true);
    }
    
    public void SendReportEmail(string userEmail, string reportPath)
    {
        string subject = "Your report is ready";
        string body = "Please find your report attached.";
        var attachments = new List<string> { reportPath };
        
        _smtpServices.SendEmail(userEmail, subject, body, 
            new List<string>(), new List<string>(), attachments);
    }
}

Sending SMS Messages

using Services.External.SmsService;

public class AlertService
{
    private readonly ISmsServices _smsServices;

    public AlertService(ISmsServices smsServices)
    {
        _smsServices = smsServices;
    }

    public void SendVerificationCode(string phoneNumber, string code)
    {
        string message = $"Your verification code is: {code}";
        _smsServices.SendSms(phoneNumber, message);
    }
    
    public void SendBulkNotification(List<string> phoneNumbers, string message)
    {
        _smsServices.SendSms(phoneNumbers, message);
    }
}

Integration with Other Moclawr Packages

This package works seamlessly with other packages in the Moclawr ecosystem:

  • Moclawr.Core: Leverages configuration models and utility extensions
  • Moclawr.Shared: Uses standardized response models for consistent error handling
  • Moclawr.Host: Perfect companion for building complete API solutions with global exception handling
  • Moclawr.Services.Caching: Cache external service responses to improve performance and reduce costs
  • Moclawr.MinimalAPI: Integrates with endpoint handlers for email/SMS functionality in APIs
  • Moclawr.DotNetCore.CAP: Use with event-driven messaging for asynchronous notifications

Requirements

  • .NET 9.0 or higher
  • Microsoft.AspNetCore.App framework reference

License

This package is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.1.0 232 5/28/2025
2.0.0 77 5/24/2025
1.0.3 80 5/24/2025
1.0.2 153 5/22/2025
1.0.1 152 5/21/2025
1.0.0 224 5/15/2025

Added improved XML documentation and bug fixes.