diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 105cfd7e..b64de555 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -88,6 +88,8 @@ PS PSP RPCS + SMTP + TLS <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> diff --git a/ProjectLighthouse/Helpers/SMTPHelper.cs b/ProjectLighthouse/Helpers/SMTPHelper.cs new file mode 100644 index 00000000..01e15869 --- /dev/null +++ b/ProjectLighthouse/Helpers/SMTPHelper.cs @@ -0,0 +1,48 @@ +using System; +using System.Net; +using System.Net.Mail; +using LBPUnion.ProjectLighthouse.Types.Settings; + +namespace LBPUnion.ProjectLighthouse.Helpers; + +public static class SMTPHelper +{ + private static readonly SmtpClient client; + private static readonly MailAddress fromAddress; + + static SMTPHelper() + { + if (!ServerSettings.Instance.SMTPEnabled) return; + + client = new SmtpClient(ServerSettings.Instance.SMTPHost, ServerSettings.Instance.SMTPPort) + { + EnableSsl = ServerSettings.Instance.SMTPSsl, + Credentials = new NetworkCredential(ServerSettings.Instance.SMTPFromAddress, ServerSettings.Instance.SMTPPassword), + }; + + fromAddress = new MailAddress(ServerSettings.Instance.SMTPFromAddress, ServerSettings.Instance.SMTPFromName); + } + + public static bool SendEmail(string recipientAddress, string subject, string body) + { + if (!ServerSettings.Instance.SMTPEnabled) return false; + + MailMessage message = new(fromAddress, new MailAddress(recipientAddress)) + { + Subject = subject, + Body = body, + }; + + try + { + client.Send(message); + } + catch(Exception e) + { + Console.WriteLine(e); + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Settings/ServerSettings.cs b/ProjectLighthouse/Types/Settings/ServerSettings.cs index 59bb9a14..ef0c885a 100644 --- a/ProjectLighthouse/Types/Settings/ServerSettings.cs +++ b/ProjectLighthouse/Types/Settings/ServerSettings.cs @@ -12,7 +12,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings; [Serializable] public class ServerSettings { - public const int CurrentConfigVersion = 22; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE! + public const int CurrentConfigVersion = 23; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE! private static FileSystemWatcher fileWatcher; static ServerSettings() { @@ -162,6 +162,24 @@ public class ServerSettings public string ServerListenUrl { get; set; } = "http://localhost:10060"; + #region SMTP + + public bool SMTPEnabled { get; set; } + + public string SMTPHost { get; set; } = ""; + + public int SMTPPort { get; set; } = 587; + + public string SMTPFromAddress { get; set; } = "lighthouse@example.com"; + + public string SMTPFromName { get; set; } = "Project Lighthouse"; + + public string SMTPPassword { get; set; } = ""; + + public bool SMTPSsl { get; set; } = true; + + #endregion + #region Meta [NotNull]