TPJ.Email
2.5.0
See the version list below for details.
dotnet add package TPJ.Email --version 2.5.0
NuGet\Install-Package TPJ.Email -Version 2.5.0
<PackageReference Include="TPJ.Email" Version="2.5.0" />
paket add TPJ.Email --version 2.5.0
#r "nuget: TPJ.Email, 2.5.0"
// Install TPJ.Email as a Cake Addin #addin nuget:?package=TPJ.Email&version=2.5.0 // Install TPJ.Email as a Cake Tool #tool nuget:?package=TPJ.Email&version=2.5.0
TPJ E-mail library - Easily send e-mails, light weight, easy to setup!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net452 is compatible. net46 is compatible. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.5.2
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.2)
- Microsoft.Extensions.Options (>= 1.0.2)
-
.NETFramework 4.6
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.2)
- Microsoft.Extensions.Options (>= 1.0.2)
-
.NETFramework 4.6.1
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.2)
- Microsoft.Extensions.Options (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
V2.5.0 is still only supporting full .net 4.5.2, 4.6, and 4.6.1. This version cleans up the code getting it ready for .NETstandard 2.0. Once .NETStandard 2.0 is released this packaged will be updated to run using this. More detailed Examples will follow then.
ASP.Net Core full framework (4.5.2 4.6 4.6.1) Website / WebAPI Set up.
Within appsettings.json and add the following
{
"TPJ": {
"Email":{
"From": "",
"SmtpClient": "",
"SmtpUser": "",
"SmtpPassword": "",
"Port": "",
"EnableSSL": ""
}
}
}
From - (Required) E-mails are sent from this account
SmtpClient – (Required) 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
Port - (Not required) port to send from
EnableSSL - (Not required) enable SSL when sending the e-mail
Example appsettings.json setup using Gmail to send error e-mails –
{
"TPJ": {
"Email":{
"From": "test@gmail.com",
"SmtpClient": "smtp.gmail.com",
"SmtpUser": "test@gmail.com",
"SmtpPassword": "testPassword",
"Port": "587",
"EnableSSL": "true"
}
}
}
Once appsettings.json is done open StartUp.cs file and go to ConfigureServices
var emailSettings = new TPJ.Email.Models.EmailSettings(Configuration);
services.Configure<TPJ.Email.Models.EmailSettings>(options =>
{
options.ApplicationName = logSettings.ApplicationName;
options.LogType = loggSettings. LogType;
options.LogFileDirectory = loggSettings.LogFileDirectory;
options.EmailTo = loggSettings.EmailTo;
options.EmailFrom = loggSettings.EmailFrom;
options.SmtpClient = loggSettings.SmtpClient;
options.SmtpUser = loggSettings.SmtpUser;
options.SmtpPassword = loggSettings.SmtpPassword;
options.Port = loggSettings.Port;
options.EnableSSL= loggSettings.EnableSSL;
});
services.AddSingleton<TPJ.Email.IEmailer, TPJ.Email.Emailer>();
Then using DI within asp.net core you can call IEmailer like so
private readonly TPJ.Email.IEmailer _email;
public HomeController(TPJ.Email.IEmailer email)
{
_email= email;
}
Then within an IActionResult you might have this
public IActionResult SendSuperEpicEmail()
{
_email.Send("epicPerson@gmail.com", "Super Epic Email", "This is a super epic email message", false);
return View();
}
This will then send an e-mail to epicPerson@gmail.com using the SMTP details you set up sending as the person you set in the config