TPJ.Email
2.2.1
See the version list below for details.
dotnet add package TPJ.Email --version 2.2.1
NuGet\Install-Package TPJ.Email -Version 2.2.1
<PackageReference Include="TPJ.Email" Version="2.2.1" />
paket add TPJ.Email --version 2.2.1
#r "nuget: TPJ.Email, 2.2.1"
// Install TPJ.Email as a Cake Addin #addin nuget:?package=TPJ.Email&version=2.2.1 // Install TPJ.Email as a Cake Tool #tool nuget:?package=TPJ.Email&version=2.2.1
TPJ.Email
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.0)
- Microsoft.Extensions.Options (>= 1.0.0)
- NETStandard.Library (>= 1.6.0)
-
.NETFramework 4.6
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Options (>= 1.0.0)
- NETStandard.Library (>= 1.6.0)
-
.NETFramework 4.6.1
- Microsoft.Extensions.Configuration.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Options (>= 1.0.0)
- NETStandard.Library (>= 1.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
New - Ability to add attachments to e-mails
ASP.Net Core Website Set up
Create appsettings.json file and add the following
{
"TPJ": {
"Email": {
"SmtpClient": "",
"SmtpUser": "",
"SmtpPassword": "",
"EmailFrom": "",
"Port": "",
"EnableSSL": ""
}
}
}
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
Port - (Not required) Port to send on
EnableSSL - (Not required) Send using SSL
For Websites -
Open StartUp.cs file and go to ConfigureServices
Add the following (I do not need port or enableSSL so have not included them)
services.Configure<TPJ.Email.Models.EmailProperties>(options =>
{
options.SmtpClient = Configuration["TPJ:Email:SmtpClient"];
options.EmailFrom = Configuration["TPJ:Email:EmailFrom"];
options.SmtpUser = Configuration["TPJ:Email:SmtpUser"];
options.SmtpPassword = Configuration["TPJ:Email: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);
return View();
}
catch (Exception e)
{
_emailer.SendEmail("test@test.co.uk", "Test Email", "Test Message", false);
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.
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);
}