TPJ.Email
1.0.0
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
<PackageReference Include="TPJ.Email" Version="1.0.0" />
paket add TPJ.Email --version 1.0.0
#r "nuget: TPJ.Email, 1.0.0"
// Install TPJ.Email as a Cake Addin #addin nuget:?package=TPJ.Email&version=1.0.0 // Install TPJ.Email as a Cake Tool #tool nuget:?package=TPJ.Email&version=1.0.0
TPJ.Email Class Library
Product | Versions 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. |
-
.NETFramework 4.5.1
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.0-rc1-final)
- Microsoft.Extensions.OptionsModel (>= 1.0.0-rc1-final)
-
DNX 4.5.1
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.0-rc1-final)
- Microsoft.Extensions.OptionsModel (>= 1.0.0-rc1-final)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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.