mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-07 07:00:33 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
77
server/FSO.Server.Api.Core/Utils/ApiMail.cs
Executable file
77
server/FSO.Server.Api.Core/Utils/ApiMail.cs
Executable file
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace FSO.Server.Api.Core.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to mail our users.
|
||||
/// Could be more useful in the future when out of Beta.
|
||||
/// </summary>
|
||||
public class ApiMail
|
||||
{
|
||||
string subject;
|
||||
string template;
|
||||
Dictionary<string, string> strings;
|
||||
|
||||
public ApiMail(string template)
|
||||
{
|
||||
this.template = template;
|
||||
this.strings = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public void AddString(string key, string value)
|
||||
{
|
||||
strings.Add(key, value);
|
||||
}
|
||||
|
||||
private string ComposeBody(Dictionary<string, string> strings)
|
||||
{
|
||||
string baseTemplate = File.ReadAllText("./MailTemplates/MailBase.html");
|
||||
string content = File.ReadAllText("./MailTemplates/" + template + ".html");
|
||||
|
||||
foreach (KeyValuePair<string, string> entry in strings)
|
||||
{
|
||||
content = content.Replace("%" + entry.Key + "%", entry.Value);
|
||||
}
|
||||
|
||||
strings = new Dictionary<string, string>();
|
||||
return baseTemplate.Replace("%content%", content);
|
||||
}
|
||||
|
||||
public bool Send(string to, string subject)
|
||||
{
|
||||
Api api = Api.INSTANCE;
|
||||
|
||||
if(api.Config.SmtpEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
MailMessage message = new MailMessage();
|
||||
message.From = new MailAddress(api.Config.SmtpUser, "FreeSO Staff");
|
||||
message.To.Add(to);
|
||||
message.Subject = subject;
|
||||
message.IsBodyHtml = true;
|
||||
message.Body = ComposeBody(strings);
|
||||
|
||||
SmtpClient client = new SmtpClient();
|
||||
client.UseDefaultCredentials = true;
|
||||
|
||||
client.Host = api.Config.SmtpHost;
|
||||
client.Port = api.Config.SmtpPort;
|
||||
client.EnableSsl = true;
|
||||
client.Credentials = new System.Net.NetworkCredential(api.Config.SmtpUser, api.Config.SmtpPassword);
|
||||
|
||||
// Send async
|
||||
client.SendMailAsync(message);
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue