Net4x.EmailLibrary 1.3.0.26248

dotnet add package Net4x.EmailLibrary --version 1.3.0.26248
                    
NuGet\Install-Package Net4x.EmailLibrary -Version 1.3.0.26248
                    
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="Net4x.EmailLibrary" Version="1.3.0.26248" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.EmailLibrary" Version="1.3.0.26248" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.EmailLibrary" />
                    
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 Net4x.EmailLibrary --version 1.3.0.26248
                    
#r "nuget: Net4x.EmailLibrary, 1.3.0.26248"
                    
#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 Net4x.EmailLibrary@1.3.0.26248
                    
#: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=Net4x.EmailLibrary&version=1.3.0.26248
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.EmailLibrary&version=1.3.0.26248
                    
Install as a Cake Tool

Net4x.EmailLibrary

Configuration-driven SMTP email sending for .NET. You supply a subject, a body and attachments; the server, port, credentials, sender, recipients, SSL and the send/dry-run switch all come from your application's configuration.

Targets net35, net40, net45 and netstandard2.0.

Install

dotnet add package Net4x.EmailLibrary

or, on legacy projects:

Install-Package Net4x.EmailLibrary

Quick start

using EmailLibrary.Mail;

// plain-text body
EmailHelper.Instance.SendEmails("Nightly report", "All jobs completed.");

// HTML body with attachments
EmailHelper.Instance.SendEmails(
    "Invoice 2024/117",
    "<p>Please find the invoice attached.</p>",
    isHtmlBody: true,
    attachments: new[] { @"C:\out\invoice-117.pdf" });

Both overloads return a System.Net.Mail.MailMessage, but do not read the return value as a delivery result: it reports whether a copy of the message was filed in the MessageDump directory, not whether the message went out. With no MessageDump configured a successful send returns null; with one configured, a send that failed still returns the message. Use logging, not the return value, to confirm delivery.

public interface IEmailHelper
{
    MailMessage SendEmails(string title, string body, params string[] attachments);
    MailMessage SendEmails(string title, string body, bool isHtmlBody, params string[] attachments);
}

Configuration

Settings are read through Net4x.Configuration.Library's ArgumentGetter, so they can come from appSettings in App.config/Web.config, a JSON configuration file, environment variables or the command line — whichever sources the host application has set up. Values are read on every send, never cached, so changing configuration at runtime takes effect immediately.

Key Type Notes
SmtpServer string SMTP host name.
SmtpPort int Defaults to 25 when absent.
UseSsl bool Enables SSL/TLS on the SMTP connection.
SmtpUserName string SMTP credentials.
SmtpPassword string SMTP credentials.
FromEmail string Sender address.
ToEmail string Recipients, joined by the configured separator. A single address needs the JSON form - see below.
CcEmail string Optional CC recipients, same format as ToEmail; empty entries are dropped.
SendEmails bool Master switch. When false, the message is logged in full but not sent, and SendEmails(...) returns null.
MessageDump string Optional directory. Belongs to the SMTP layer rather than this library, but it changes both the return value and how failures surface - see below.

Example App.config:

<configuration>
  <appSettings>
    <add key="SmtpServer" value="smtp.example.com" />
    <add key="SmtpPort" value="587" />
    <add key="UseSsl" value="true" />
    <add key="SmtpUserName" value="noreply@example.com" />
    <add key="SmtpPassword" value="..." />
    <add key="FromEmail" value="noreply@example.com" />
    <add key="ToEmail" value="ops@example.com|audit@example.com" />
    <add key="CcEmail" value="" />
    <add key="SendEmails" value="true" />
  </appSettings>
</configuration>

ToEmail and CcEmail are split into multiple addresses using ArgumentGetter.Instance.Separator (| by default); set that property to match the delimiter you use.

A value that contains no separator is not treated as a one-element list - it is parsed as JSON instead. So a single recipient must be written as a JSON array, or the setting resolves to no recipients at all:


<add key="ToEmail" value="ops@example.com|audit@example.com" />


<add key="ToEmail" value='["ops@example.com"]' />

CC recipients are delivered, but the current SMTP layer places them on the To header rather than a Cc header.

Dry runs

Leaving SendEmails set to false is the intended way to exercise an integration without delivering mail. The subject, sender, recipients, CC list and every attachment path are still written to the log — only the SMTP call is skipped.

Renaming the configuration keys

If your application already stores these settings under different names, do not rename your configuration: supply your own key names and build the configuration accessor yourself.

using EmailLibrary.Interfaces.Model;
using EmailLibrary.Model;

IMailConfigurationConstants keys = new MailConfigurationConstants
{
    SmtpServer = "Mail:Host",
    SmtpPort   = "Mail:Port",
    FromEmail  = "Mail:Sender",
    ToEmail    = "Mail:Recipients",
    SendEmails = "Mail:Enabled",
};

IMailConfigurationVariables mail = MailConfigurationVariables.CreateInstance(keys);

int port = mail.SmtpPort;                      // typed read, defaults to 25
mail.ToEmail = new[] { "a@b.com", "c@d.com" }; // typed write, persisted through ArgumentGetter

IMailConfigurationVariables exposes every setting as a typed, read/write property (string, int, bool, string[]), which also makes it a convenient way to inspect or adjust mail configuration from code.

Logging and error handling

The library logs through CoreLibrary.Logging.LoggerFactory, using whichever logger the host application has registered. Each call logs a one-line summary — [subject] email from: … to: … cc: … — followed by the attachment list. Messages are localized; English and Italian (it-IT) are included.

How a delivery failure surfaces depends on whether a MessageDump directory is configured:

  • Without MessageDump an SmtpException propagates to the caller.
  • With MessageDump nothing is thrown; the failure is recorded as a .txt note beside the saved copy of the message, and logged.

Set MessageDump to a writable directory if you would rather handle failures from your logs than from exceptions.

Dependencies

  • Net4x.Configuration.Library — configuration access
  • Net4x.DataAccessLibrary.Web — SMTP delivery
  • Net4x.DataAccessLibrary.Data.Work

Copyright: Copyright (c) Piero Viano. All rights reserved. Authors: Piero Viano Company: Piero Viano

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.3.0.26248 103 9/5/2026
1.3.0.26247 108 9/4/2026
1.3.0.26246 172 9/3/2026
1.3.0 392 4/4/2025
1.1.0 565 8/26/2023