mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-03 08:10:43 +00:00
Add SMTP support
This commit is contained in:
parent
36ce61697f
commit
3bba7eff1b
3 changed files with 69 additions and 1 deletions
|
@ -88,6 +88,8 @@
|
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PS/@EntryIndexedValue">PS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PSP/@EntryIndexedValue">PSP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RPCS/@EntryIndexedValue">RPCS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SMTP/@EntryIndexedValue">SMTP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TLS/@EntryIndexedValue">TLS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
|
|
48
ProjectLighthouse/Helpers/SMTPHelper.cs
Normal file
48
ProjectLighthouse/Helpers/SMTPHelper.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue