Skip to content

Commit c8abfc4

Browse files
committed
initial commit
1 parent 35d7fb9 commit c8abfc4

35 files changed

+86579
-0
lines changed
5.96 KB
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"runtimeTarget": {
3+
"name": ".NETCoreApp,Version=v8.0",
4+
"signature": ""
5+
},
6+
"compilationOptions": {},
7+
"targets": {
8+
".NETCoreApp,Version=v8.0": {
9+
"CSO.Email/0.0.1": {
10+
"dependencies": {
11+
"Newtonsoft.Json": "13.0.3"
12+
},
13+
"runtime": {
14+
"CSO.Email.dll": {}
15+
}
16+
},
17+
"Newtonsoft.Json/13.0.3": {
18+
"runtime": {
19+
"lib/net6.0/Newtonsoft.Json.dll": {
20+
"assemblyVersion": "13.0.0.0",
21+
"fileVersion": "13.0.3.27908"
22+
}
23+
}
24+
}
25+
}
26+
},
27+
"libraries": {
28+
"CSO.Email/0.0.1": {
29+
"type": "project",
30+
"serviceable": false,
31+
"sha512": ""
32+
},
33+
"Newtonsoft.Json/13.0.3": {
34+
"type": "package",
35+
"serviceable": true,
36+
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
37+
"path": "newtonsoft.json/13.0.3",
38+
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512"
39+
}
40+
}
41+
}

rls/0.0.1BETA/net8.0/CSO.Email.dll

9.5 KB
Binary file not shown.

rls/0.0.1BETA/net8.0/CSO.Email.pdb

20.6 KB
Binary file not shown.

src/CSO.Email.sln

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32630.192
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE5B5136-CEE7-40AE-A799-A364D1A27D20}"
7+
ProjectSection(SolutionItems) = preProject
8+
nuget.config = nuget.config
9+
EndProjectSection
10+
EndProject
11+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSO.Email", "CSO.Email\CSO.Email.csproj", "{0E2DE3C2-8090-410D-93E3-36340CD50798}"
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|Any CPU = Debug|Any CPU
16+
Debug|x64 = Debug|x64
17+
Dev|Any CPU = Dev|Any CPU
18+
Dev|x64 = Dev|x64
19+
Live|Any CPU = Live|Any CPU
20+
Live|x64 = Live|x64
21+
Release|Any CPU = Release|Any CPU
22+
Release|x64 = Release|x64
23+
TD|Any CPU = TD|Any CPU
24+
TD|x64 = TD|x64
25+
EndGlobalSection
26+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
27+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|x64.ActiveCfg = Debug|x64
30+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Debug|x64.Build.0 = Debug|x64
31+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|Any CPU.ActiveCfg = Debug|Any CPU
32+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|Any CPU.Build.0 = Debug|Any CPU
33+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|x64.ActiveCfg = Debug|x64
34+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Dev|x64.Build.0 = Debug|x64
35+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|Any CPU.ActiveCfg = Debug|Any CPU
36+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|Any CPU.Build.0 = Debug|Any CPU
37+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|x64.ActiveCfg = Debug|x64
38+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Live|x64.Build.0 = Debug|x64
39+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|x64.ActiveCfg = Release|x64
42+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.Release|x64.Build.0 = Release|x64
43+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|Any CPU.ActiveCfg = Debug|Any CPU
44+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|Any CPU.Build.0 = Debug|Any CPU
45+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|x64.ActiveCfg = Debug|x64
46+
{0E2DE3C2-8090-410D-93E3-36340CD50798}.TD|x64.Build.0 = Debug|x64
47+
EndGlobalSection
48+
GlobalSection(SolutionProperties) = preSolution
49+
HideSolutionNode = FALSE
50+
EndGlobalSection
51+
GlobalSection(ExtensibilityGlobals) = postSolution
52+
SolutionGuid = {C633644D-71C0-4CF2-95D0-F6C367931EB3}
53+
EndGlobalSection
54+
EndGlobal

src/CSO.Email/CSO.Email.csproj

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Platforms>AnyCPU;x64</Platforms>
7+
<TargetFramework>net8.0</TargetFramework>
8+
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
9+
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
10+
<Configuration></Configuration>
11+
<Company>Central Statistics Office, Ireland</Company>
12+
<PackageId>CSO.Email.BETA</PackageId>
13+
<Product>CSO.Email</Product>
14+
<Copyright>Central Statistics Office, Ireland</Copyright>
15+
<Version>0.0.1</Version>
16+
<Authors>Central Statistics Office, Ireland</Authors>
17+
<SignAssembly>False</SignAssembly>
18+
<RepositoryUrl>https://github.com/CSOIreland/CSOEmail</RepositoryUrl>
19+
<PackageReleaseNotes>
20+
- [INFO] initial release of CSO standalone email library
21+
</PackageReleaseNotes>
22+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
23+
<RestoreLockedMode>true</RestoreLockedMode>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<Compile Remove="bin\**" />
28+
<EmbeddedResource Remove="bin\**" />
29+
<None Remove="bin\**" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<None Remove="Entities\ADO.cs~RF5780ef96.TMP" />
34+
<None Remove="Entities\API.Common.cs~RF1e6b9c0d.TMP" />
35+
<None Remove="Entities\MemCacheD.cs~RFcba3198.TMP" />
36+
<None Remove="log4net.config" />
37+
</ItemGroup>
38+
39+
40+
<ItemGroup>
41+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
42+
</ItemGroup>
43+
44+
<ItemGroup>
45+
<Folder Include="Properties\" />
46+
47+
</ItemGroup>
48+
49+
<ItemGroup>
50+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
51+
</ItemGroup>
52+
53+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
54+
<Optimize>False</Optimize>
55+
<DebugType>portable</DebugType>
56+
</PropertyGroup>
57+
58+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
59+
<DebugType>portable</DebugType>
60+
</PropertyGroup>
61+
62+
</Project>

src/CSO.Email/Entities/eMail.cs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
using System.Net.Mail;
2+
using Newtonsoft.Json;
3+
4+
namespace CSO.Email
5+
{
6+
/// <summary>
7+
/// Mail Message
8+
/// </summary>
9+
public class eMail : MailMessage
10+
{
11+
#region Properties
12+
#endregion
13+
public eMail()
14+
{
15+
}
16+
17+
18+
#region Methods
19+
/// <summary>
20+
/// Send an Email
21+
/// </summary>
22+
/// <param name="configDict"></param>
23+
/// <param name="LogObject"></param>
24+
/// <returns></returns>
25+
public bool Send(IDictionary<string, string> configDict, dynamic LogObject)
26+
{
27+
/// <summary>
28+
/// Swtich on/off the service
29+
/// </summary>
30+
bool API_EMAIL_ENABLED = Convert.ToBoolean(configDict["API_EMAIL_ENABLED"]);
31+
32+
/// <summary>
33+
/// NoReply email address
34+
/// </summary>
35+
string API_EMAIL_MAIL_NOREPLY = configDict["API_EMAIL_MAIL_NOREPLY"];
36+
37+
/// <summary>
38+
/// Sender email address
39+
/// </summary>
40+
string API_EMAIL_MAIL_SENDER = configDict["API_EMAIL_MAIL_SENDER"];
41+
42+
/// <summary>
43+
/// Server IP address
44+
/// </summary>
45+
string API_EMAIL_SMTP_SERVER = configDict["API_EMAIL_SMTP_SERVER"];
46+
47+
/// <summary>
48+
/// Port number
49+
/// </summary>
50+
string API_EMAIL_SMTP_PORT = configDict["API_EMAIL_SMTP_PORT"];
51+
52+
/// <summary>
53+
/// Flag to indicate if SMTP authentication is required
54+
/// </summary>
55+
bool API_EMAIL_SMTP_AUTHENTICATION = Convert.ToBoolean(configDict["API_EMAIL_SMTP_AUTHENTICATION"]);
56+
57+
/// <summary>
58+
/// Username if authentication is required
59+
/// </summary>
60+
string API_EMAIL_SMTP_USERNAME = configDict["API_EMAIL_SMTP_USERNAME"];
61+
62+
/// <summary>
63+
/// Password if authentication is required
64+
/// </summary>
65+
string API_EMAIL_SMTP_PASSWORD = configDict["API_EMAIL_SMTP_PASSWORD"];
66+
67+
/// <summary>
68+
/// Flag to indicate if SSL is required
69+
/// </summary>
70+
bool API_EMAIL_SMTP_SSL = Convert.ToBoolean(configDict["API_EMAIL_SMTP_SSL"]);
71+
72+
/// <summary>
73+
/// Template Datetime Mask
74+
/// </summary>
75+
// private readonly string API_EMAIL_DATETIME_MASK = ApiServicesHelper.ApiConfiguration.Settings["API_EMAIL_DATETIME_MASK"];
76+
77+
LogObject.Info("Email Enabled: " + API_EMAIL_ENABLED);
78+
LogObject.Info("Email NoReply: " + API_EMAIL_MAIL_NOREPLY);
79+
LogObject.Info("Email Sender: " + API_EMAIL_MAIL_SENDER);
80+
LogObject.Info("SMTP Server: " + API_EMAIL_SMTP_SERVER);
81+
LogObject.Info("SMTP Port: " + API_EMAIL_SMTP_PORT);
82+
LogObject.Info("SMTP Authentication: " + API_EMAIL_SMTP_AUTHENTICATION);
83+
LogObject.Info("SMTP Username: " + API_EMAIL_SMTP_USERNAME);
84+
LogObject.Info("SMTP Password: ********"); // Hide API_EMAIL_SMTP_PAsSSWORD from logs
85+
LogObject.Info("SMTP SSL: " + API_EMAIL_SMTP_SSL);
86+
87+
if (!API_EMAIL_ENABLED)
88+
{
89+
return false;
90+
}
91+
92+
try
93+
{
94+
// Initiate new SMTP Client
95+
SmtpClient smtpClient = new SmtpClient(API_EMAIL_SMTP_SERVER, Convert.ToInt32(API_EMAIL_SMTP_PORT));
96+
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
97+
98+
if (API_EMAIL_SMTP_AUTHENTICATION
99+
&& !string.IsNullOrWhiteSpace(API_EMAIL_SMTP_USERNAME)
100+
&& !string.IsNullOrWhiteSpace(API_EMAIL_SMTP_PASSWORD))
101+
{
102+
// Use authentication if any
103+
smtpClient.Credentials = new System.Net.NetworkCredential(API_EMAIL_SMTP_USERNAME, API_EMAIL_SMTP_PASSWORD);
104+
smtpClient.UseDefaultCredentials = true;
105+
}
106+
107+
if (API_EMAIL_SMTP_SSL)
108+
{
109+
// Use SSL if any
110+
smtpClient.EnableSsl = true;
111+
}
112+
113+
// Override Sender, From, Reply To for security
114+
this.ReplyToList.Clear();
115+
this.ReplyToList.Add(new MailAddress(API_EMAIL_MAIL_NOREPLY));
116+
this.From = new MailAddress(API_EMAIL_MAIL_SENDER);
117+
this.Sender = new MailAddress(API_EMAIL_MAIL_SENDER);
118+
119+
// Set the HTML body
120+
this.IsBodyHtml = true;
121+
122+
// Send the mail
123+
smtpClient.Send(this);
124+
125+
LogObject.Info("eMail sent");
126+
return true;
127+
}
128+
catch (Exception e)
129+
{
130+
LogObject.Fatal(e);
131+
return false;
132+
}
133+
}
134+
135+
/// <summary>
136+
/// Parse a Template located in Properties.Resources
137+
/// </summary>
138+
/// <param name="template"></param>
139+
/// <param name="eMail_KeyValuePair"></param>
140+
/// <param name="LogObject"></param>
141+
/// <returns></returns>
142+
public string ParseTemplate(string template, List<eMail_KeyValuePair> eMail_KeyValuePair, dynamic LogObject)
143+
{
144+
145+
LogObject.Info("eMail String-Template to parse: " + template);
146+
LogObject.Info("eMail List to parse: " + JsonConvert.SerializeObject(eMail_KeyValuePair, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
147+
try
148+
{
149+
// Parse nodes
150+
foreach (var item in eMail_KeyValuePair)
151+
{
152+
template = template.Replace(item.key, item.value);
153+
}
154+
155+
return template;
156+
157+
}
158+
catch (Exception e)
159+
{
160+
LogObject.Fatal(e);
161+
throw;
162+
}
163+
}
164+
#endregion
165+
}
166+
167+
public class eMail_KeyValuePair
168+
{
169+
#region Properties
170+
/// <summary>
171+
/// Key to parse
172+
/// </summary>
173+
public string key { get; set; }
174+
175+
/// <summary>
176+
/// Value to parse
177+
/// </summary>
178+
public string value { get; set; }
179+
180+
#endregion
181+
182+
/// <summary>
183+
/// Initialise a blank one
184+
/// </summary>
185+
public eMail_KeyValuePair()
186+
{
187+
key = null;
188+
value = null;
189+
}
190+
}
191+
192+
}

0 commit comments

Comments
 (0)