TPJ.Email 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TPJ.Email --version 1.0.0
                    
NuGet\Install-Package TPJ.Email -Version 1.0.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="TPJ.Email" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TPJ.Email" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TPJ.Email" />
                    
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 TPJ.Email --version 1.0.0
                    
#r "nuget: TPJ.Email, 1.0.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 TPJ.Email@1.0.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=TPJ.Email&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TPJ.Email&version=1.0.0
                    
Install as a Cake Tool

TPJ.Email Class Library

Product Compatible and additional computed target framework versions.
.NET Framework net451 is compatible.  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. 
DNX dnx451 is compatible. 
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
9.0.0 112 12/18/2024
4.0.0 375 1/22/2023
3.0.0 1,426 8/20/2017
2.5.0 1,364 5/4/2017
2.3.0 1,794 10/6/2016
2.2.1 1,585 8/30/2016
1.0.0 2,756 4/19/2016

ASP.Net Core Website Set up

Create appsettings.json file and add the following

"EmailSettings": {
   "SmtpClient": "",
   "SmtpUser": "",
   "SmtpPassword": "",
   "EmailFrom": ""
}


SmtpClient - SMTP server which e-mails will be sent from

SmtpUser - (Not required) send e-mail using the given user name and password
SmtpPassword - (Not required) send e-mail using the given user name and password

EmailFrom - E-mails are sent from this account


For Websites -

Open StartUp.cs file and go to ConfigureServices

Add the following

services.Configure<EmailProperties>(options =>
{
    options.SmtpClient = Configuration["EmailSettings:SmtpClient"];
    options.EmailFrom = Configuration["EmailSettings:EmailFrom"];
    options.SmtpUser = Configuration["EmailSettings:SmtpUser"];
    options.SmtpPassword = Configuration["EmailSettings:SmtpPassword"];
});

services.AddTransient<TPJ.Email.Interfaces.IEmailer, TPJ.Email.Emailer>();

Then using DI within asp.net core you can call IEmailerlike so

private readonly TPJ.Email.Interfaces.IEmailer _emailer;

public HomeController(TPJ.Email.Interfaces.IEmailer emailer)
{
   _emailer = emailer;
}

Then within an IActionResult you might have this

public IActionResult About()
{
 try
 {
   _logger.InformationLog("About Page Loaded", Enums.LogEnvironment.Development, true);

   return View();

 }
 catch (Exception e)
 {
    _emailer.SendEmail("test@test.co.uk", "Test Email", "Test Message", false, true);

   return RedirectToAction(nameof(Error));
 }
}

Here an e-mail will be sent to test@Test.co.uk with the subject of Test Email saying Test Message. The message content is not html and do fire and forget to improve loading times


ASP.Net Core Console Application

This is how I do it. This may change and I'm sure there are different ways to do this. This is also just to get the logger to work. You may need to change things to get other packages to load.

Add to the top of the program class

public static IEmailer _emailer;

Then add set up method

private static void SetUp()
{
   var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
   
   var configuration = builder.Build();
   _emailer = new Emailer(new TPJ.Email.Models.EmailProperties(configuration));
}

Then call the "SetUp" method from the Main method

public static void Main(string[] args)
{
   SetUp();
}

Then you can call the logger like so

public static void Main(string[] args)
{
   SetUp();

    _emailer.SendEmail("test@test.co.uk", "Test Email", "Test Message", false, false);
}

With console application do not "fire and forget" as if the application ends and the log is not completed it will not log.