mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-10 20:22:28 +00:00
- Sorts config better - Stored in a robust format - Migrates from old JSON format automatically on startup - Retains version migration feature - Renames ServerSettings to ServerConfiguration
48 lines
No EOL
1.4 KiB
C#
48 lines
No EOL
1.4 KiB
C#
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 (!ServerConfiguration.Instance.Mail.MailEnabled) return;
|
|
|
|
client = new SmtpClient(ServerConfiguration.Instance.Mail.Host, ServerConfiguration.Instance.Mail.Port)
|
|
{
|
|
EnableSsl = ServerConfiguration.Instance.Mail.UseSSL,
|
|
Credentials = new NetworkCredential(ServerConfiguration.Instance.Mail.FromAddress, ServerConfiguration.Instance.Mail.Password),
|
|
};
|
|
|
|
fromAddress = new MailAddress(ServerConfiguration.Instance.Mail.FromAddress, ServerConfiguration.Instance.Mail.FromName);
|
|
}
|
|
|
|
public static bool SendEmail(string recipientAddress, string subject, string body)
|
|
{
|
|
if (!ServerConfiguration.Instance.Mail.MailEnabled) 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;
|
|
}
|
|
} |