-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
86,579 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v8.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v8.0": { | ||
"CSO.Email/0.0.1": { | ||
"dependencies": { | ||
"Newtonsoft.Json": "13.0.3" | ||
}, | ||
"runtime": { | ||
"CSO.Email.dll": {} | ||
} | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"runtime": { | ||
"lib/net6.0/Newtonsoft.Json.dll": { | ||
"assemblyVersion": "13.0.0.0", | ||
"fileVersion": "13.0.3.27908" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"CSO.Email/0.0.1": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"type": "package", | ||
"serviceable": true, | ||
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", | ||
"path": "newtonsoft.json/13.0.3", | ||
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.2.32630.192 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE5B5136-CEE7-40AE-A799-A364D1A27D20}" | ||
ProjectSection(SolutionItems) = preProject | ||
nuget.config = nuget.config | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSO.Email", "CSO.Email\CSO.Email.csproj", "{0E2DE3C2-8090-410D-93E3-36340CD50798}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Dev|Any CPU = Dev|Any CPU | ||
Dev|x64 = Dev|x64 | ||
Live|Any CPU = Live|Any CPU | ||
Live|x64 = Live|x64 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
TD|Any CPU = TD|Any CPU | ||
TD|x64 = TD|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|x64.ActiveCfg = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|x64.Build.0 = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|Any CPU.Build.0 = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|x64.ActiveCfg = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|x64.Build.0 = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|Any CPU.Build.0 = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|x64.ActiveCfg = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|x64.Build.0 = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|x64.ActiveCfg = Release|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|x64.Build.0 = Release|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|Any CPU.Build.0 = Debug|Any CPU | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|x64.ActiveCfg = Debug|x64 | ||
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|x64.Build.0 = Debug|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C633644D-71C0-4CF2-95D0-F6C367931EB3} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> | ||
<GenerateAssemblyInfo>True</GenerateAssemblyInfo> | ||
<Configuration></Configuration> | ||
<Company>Central Statistics Office, Ireland</Company> | ||
<PackageId>CSO.Email.BETA</PackageId> | ||
<Product>CSO.Email</Product> | ||
<Copyright>Central Statistics Office, Ireland</Copyright> | ||
<Version>0.0.1</Version> | ||
<Authors>Central Statistics Office, Ireland</Authors> | ||
<SignAssembly>False</SignAssembly> | ||
<RepositoryUrl>https://github.com/CSOIreland/CSOEmail</RepositoryUrl> | ||
<PackageReleaseNotes> | ||
- [INFO] initial release of CSO standalone email library | ||
</PackageReleaseNotes> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
<RestoreLockedMode>true</RestoreLockedMode> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="bin\**" /> | ||
<EmbeddedResource Remove="bin\**" /> | ||
<None Remove="bin\**" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Entities\ADO.cs~RF5780ef96.TMP" /> | ||
<None Remove="Entities\API.Common.cs~RF1e6b9c0d.TMP" /> | ||
<None Remove="Entities\MemCacheD.cs~RFcba3198.TMP" /> | ||
<None Remove="log4net.config" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
|
||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<Optimize>False</Optimize> | ||
<DebugType>portable</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DebugType>portable</DebugType> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
using System.Net.Mail; | ||
using Newtonsoft.Json; | ||
|
||
namespace CSO.Email | ||
{ | ||
/// <summary> | ||
/// Mail Message | ||
/// </summary> | ||
public class eMail : MailMessage | ||
{ | ||
#region Properties | ||
#endregion | ||
public eMail() | ||
{ | ||
} | ||
|
||
|
||
#region Methods | ||
/// <summary> | ||
/// Send an Email | ||
/// </summary> | ||
/// <param name="configDict"></param> | ||
/// <param name="LogObject"></param> | ||
/// <returns></returns> | ||
public bool Send(IDictionary<string, string> configDict, dynamic LogObject) | ||
{ | ||
/// <summary> | ||
/// Swtich on/off the service | ||
/// </summary> | ||
bool API_EMAIL_ENABLED = Convert.ToBoolean(configDict["API_EMAIL_ENABLED"]); | ||
|
||
/// <summary> | ||
/// NoReply email address | ||
/// </summary> | ||
string API_EMAIL_MAIL_NOREPLY = configDict["API_EMAIL_MAIL_NOREPLY"]; | ||
|
||
/// <summary> | ||
/// Sender email address | ||
/// </summary> | ||
string API_EMAIL_MAIL_SENDER = configDict["API_EMAIL_MAIL_SENDER"]; | ||
|
||
/// <summary> | ||
/// Server IP address | ||
/// </summary> | ||
string API_EMAIL_SMTP_SERVER = configDict["API_EMAIL_SMTP_SERVER"]; | ||
|
||
/// <summary> | ||
/// Port number | ||
/// </summary> | ||
string API_EMAIL_SMTP_PORT = configDict["API_EMAIL_SMTP_PORT"]; | ||
|
||
/// <summary> | ||
/// Flag to indicate if SMTP authentication is required | ||
/// </summary> | ||
bool API_EMAIL_SMTP_AUTHENTICATION = Convert.ToBoolean(configDict["API_EMAIL_SMTP_AUTHENTICATION"]); | ||
|
||
/// <summary> | ||
/// Username if authentication is required | ||
/// </summary> | ||
string API_EMAIL_SMTP_USERNAME = configDict["API_EMAIL_SMTP_USERNAME"]; | ||
|
||
/// <summary> | ||
/// Password if authentication is required | ||
/// </summary> | ||
string API_EMAIL_SMTP_PASSWORD = configDict["API_EMAIL_SMTP_PASSWORD"]; | ||
|
||
/// <summary> | ||
/// Flag to indicate if SSL is required | ||
/// </summary> | ||
bool API_EMAIL_SMTP_SSL = Convert.ToBoolean(configDict["API_EMAIL_SMTP_SSL"]); | ||
|
||
/// <summary> | ||
/// Template Datetime Mask | ||
/// </summary> | ||
// private readonly string API_EMAIL_DATETIME_MASK = ApiServicesHelper.ApiConfiguration.Settings["API_EMAIL_DATETIME_MASK"]; | ||
|
||
LogObject.Info("Email Enabled: " + API_EMAIL_ENABLED); | ||
LogObject.Info("Email NoReply: " + API_EMAIL_MAIL_NOREPLY); | ||
LogObject.Info("Email Sender: " + API_EMAIL_MAIL_SENDER); | ||
LogObject.Info("SMTP Server: " + API_EMAIL_SMTP_SERVER); | ||
LogObject.Info("SMTP Port: " + API_EMAIL_SMTP_PORT); | ||
LogObject.Info("SMTP Authentication: " + API_EMAIL_SMTP_AUTHENTICATION); | ||
LogObject.Info("SMTP Username: " + API_EMAIL_SMTP_USERNAME); | ||
LogObject.Info("SMTP Password: ********"); // Hide API_EMAIL_SMTP_PAsSSWORD from logs | ||
LogObject.Info("SMTP SSL: " + API_EMAIL_SMTP_SSL); | ||
|
||
if (!API_EMAIL_ENABLED) | ||
{ | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
// Initiate new SMTP Client | ||
SmtpClient smtpClient = new SmtpClient(API_EMAIL_SMTP_SERVER, Convert.ToInt32(API_EMAIL_SMTP_PORT)); | ||
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; | ||
|
||
if (API_EMAIL_SMTP_AUTHENTICATION | ||
&& !string.IsNullOrWhiteSpace(API_EMAIL_SMTP_USERNAME) | ||
&& !string.IsNullOrWhiteSpace(API_EMAIL_SMTP_PASSWORD)) | ||
{ | ||
// Use authentication if any | ||
smtpClient.Credentials = new System.Net.NetworkCredential(API_EMAIL_SMTP_USERNAME, API_EMAIL_SMTP_PASSWORD); | ||
smtpClient.UseDefaultCredentials = true; | ||
} | ||
|
||
if (API_EMAIL_SMTP_SSL) | ||
{ | ||
// Use SSL if any | ||
smtpClient.EnableSsl = true; | ||
} | ||
|
||
// Override Sender, From, Reply To for security | ||
this.ReplyToList.Clear(); | ||
this.ReplyToList.Add(new MailAddress(API_EMAIL_MAIL_NOREPLY)); | ||
this.From = new MailAddress(API_EMAIL_MAIL_SENDER); | ||
this.Sender = new MailAddress(API_EMAIL_MAIL_SENDER); | ||
|
||
// Set the HTML body | ||
this.IsBodyHtml = true; | ||
|
||
// Send the mail | ||
smtpClient.Send(this); | ||
|
||
LogObject.Info("eMail sent"); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
LogObject.Fatal(e); | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Parse a Template located in Properties.Resources | ||
/// </summary> | ||
/// <param name="template"></param> | ||
/// <param name="eMail_KeyValuePair"></param> | ||
/// <param name="LogObject"></param> | ||
/// <returns></returns> | ||
public string ParseTemplate(string template, List<eMail_KeyValuePair> eMail_KeyValuePair, dynamic LogObject) | ||
{ | ||
|
||
LogObject.Info("eMail String-Template to parse: " + template); | ||
LogObject.Info("eMail List to parse: " + JsonConvert.SerializeObject(eMail_KeyValuePair, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None, ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); | ||
try | ||
{ | ||
// Parse nodes | ||
foreach (var item in eMail_KeyValuePair) | ||
{ | ||
template = template.Replace(item.key, item.value); | ||
} | ||
|
||
return template; | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
LogObject.Fatal(e); | ||
throw; | ||
} | ||
} | ||
#endregion | ||
} | ||
|
||
public class eMail_KeyValuePair | ||
{ | ||
#region Properties | ||
/// <summary> | ||
/// Key to parse | ||
/// </summary> | ||
public string key { get; set; } | ||
|
||
/// <summary> | ||
/// Value to parse | ||
/// </summary> | ||
public string value { get; set; } | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// Initialise a blank one | ||
/// </summary> | ||
public eMail_KeyValuePair() | ||
{ | ||
key = null; | ||
value = null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.