diff --git a/StockMan.CORE.sln b/StockMan.CORE.sln new file mode 100644 index 0000000..4b572d0 --- /dev/null +++ b/StockMan.CORE.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockMan.CORE", "StockMan.CORE\StockMan.CORE.csproj", "{3D23F328-E6B6-4EDB-B2DE-00E39E953757}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockMan.Data", "StockMan.Data\StockMan.Data.csproj", "{5C4C9C5C-9478-424A-B68C-C3C04C5E2165}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3D23F328-E6B6-4EDB-B2DE-00E39E953757}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D23F328-E6B6-4EDB-B2DE-00E39E953757}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D23F328-E6B6-4EDB-B2DE-00E39E953757}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D23F328-E6B6-4EDB-B2DE-00E39E953757}.Release|Any CPU.Build.0 = Release|Any CPU + {5C4C9C5C-9478-424A-B68C-C3C04C5E2165}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C4C9C5C-9478-424A-B68C-C3C04C5E2165}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C4C9C5C-9478-424A-B68C-C3C04C5E2165}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C4C9C5C-9478-424A-B68C-C3C04C5E2165}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3FB1DC7D-579E-4165-9A0A-8E6D8C12FC75} + EndGlobalSection +EndGlobal diff --git a/StockMan.Data/MailKitEmailSender.cs b/StockMan.Data/MailKitEmailSender.cs new file mode 100644 index 0000000..0bdfcec --- /dev/null +++ b/StockMan.Data/MailKitEmailSender.cs @@ -0,0 +1,68 @@ +using Microsoft.Extensions.Options; +using MimeKit.Text; +using MimeKit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MailKit.Net.Smtp; +using Microsoft.AspNetCore.Identity.UI.Services; + +namespace StockMan.Data +{ + /// Implementazione interfaccia email con pacchetto MailKIT + /// + /// https://www.ryadel.com/en/asp-net-core-send-email-messages-smtp-mailkit/ + /// + public class MailKitEmailSender : IEmailSender + { + #region Public Constructors + + public MailKitEmailSender(IOptions options) + { + this.Options = options.Value; + } + + #endregion Public Constructors + + #region Public Properties + + public MailKitEmailSenderOptions Options { get; set; } + + #endregion Public Properties + + #region Public Methods + + public Task Execute(string to, string subject, string message) + { + // create message + var email = new MimeMessage(); + email.Sender = MailboxAddress.Parse(Options.Sender_EMail); + if (!string.IsNullOrEmpty(Options.Sender_Name)) + email.Sender.Name = Options.Sender_Name; + email.From.Add(email.Sender); + email.To.Add(MailboxAddress.Parse(to)); + email.Subject = subject; + email.Body = new TextPart(TextFormat.Html) { Text = message }; + + // send email + using (var smtp = new SmtpClient()) + { + smtp.Connect(Options.Host_Address, Options.Host_Port, Options.Host_SecureSocketOptions); + smtp.Authenticate(Options.Host_Username, Options.Host_Password); + smtp.Send(email); + smtp.Disconnect(true); + } + + return Task.FromResult(true); + } + + public Task SendEmailAsync(string email, string subject, string message) + { + return Execute(email, subject, message); + } + + #endregion Public Methods + } +} diff --git a/StockMan.Data/MailKitEmailSenderOptions.cs b/StockMan.Data/MailKitEmailSenderOptions.cs new file mode 100644 index 0000000..3a83699 --- /dev/null +++ b/StockMan.Data/MailKitEmailSenderOptions.cs @@ -0,0 +1,36 @@ +using MailKit.Security; + +namespace StockMan.Data +{ + public class MailKitEmailSenderOptions + { + #region Public Constructors + + public MailKitEmailSenderOptions() + { + Host_SecureSocketOptions = SecureSocketOptions.Auto; + Host_Address = "127.0.0.1"; + Host_Password = ""; + Host_Username = ""; + Sender_EMail = "info@steamware.net"; + Sender_Name = "Info Steamware"; + } + + #endregion Public Constructors + + #region Public Properties + + public string Host_Address { get; set; } + + public string Host_Password { get; set; } + public int Host_Port { get; set; } + + public SecureSocketOptions Host_SecureSocketOptions { get; set; } + public string Host_Username { get; set; } + public string Sender_EMail { get; set; } + + public string Sender_Name { get; set; } + + #endregion Public Properties + } +} diff --git a/StockMan.Data/QHelper.cs b/StockMan.Data/QHelper.cs new file mode 100644 index 0000000..efa490e --- /dev/null +++ b/StockMan.Data/QHelper.cs @@ -0,0 +1,21 @@ +namespace StockMan.Data +{ + public class QHelper + { + #region Public Methods + + /// + /// Blazor: get query parm from the URL + /// + /// + /// + public static string GetQueryParm(string fullUri, string parmName) + { + var uriBuilder = new UriBuilder(fullUri); + var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query); + return q[parmName] ?? ""; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/StockMan.Data/StockMan.Data.csproj b/StockMan.Data/StockMan.Data.csproj new file mode 100644 index 0000000..f68d35c --- /dev/null +++ b/StockMan.Data/StockMan.Data.csproj @@ -0,0 +1,35 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + +