feat: email config is now loaded from fs

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-12 14:29:29 +02:00
parent 31409be192
commit 766e6054dc
4 changed files with 19 additions and 3 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@ ImageBoardServerApp/wwwroot/img/dynamic
*.db-shm
*.db-wal
Migrations/
/ImageBoardServerApp/Data/creds.json
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

View file

@ -15,6 +15,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Radzen.Blazor" Version="4.10.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

View file

@ -44,6 +44,9 @@ ImageThumbnailOptions options = new ImageThumbnailOptions("wwwroot/img/", "thumb
options.ImageQuality = 75L;
app.UseImageThumbnail(options);
//Load mail config
Postman.loadConfig();
//Log onto Mail Server
Postman.logon();

View file

@ -1,25 +1,36 @@
using System.Net;
using System.Net.Mail;
using Newtonsoft.Json;
namespace ImageBoardServerApp.Util;
public static class Postman
{
private static SmtpClient smtpClient;
public static Dictionary<string, object> values = new Dictionary<string, object>();
public static void loadConfig()
{
values =
JsonConvert.DeserializeObject<Dictionary<string, object>>(File.ReadAllText("Data/creds.json"));
Console.WriteLine(File.ReadAllText("Data/creds.json"));
}
public static void logon()
{
smtpClient = new SmtpClient("smtp.bulletboards.xyz")
smtpClient = new SmtpClient(values["email-server"].ToString())
{
Port = 587,
Credentials = new NetworkCredential("noreply@bulletboards.xyz", "frogARdI,97,#"),
Credentials = new NetworkCredential(values["email-address"].ToString(), values["email-password"].ToString()),
EnableSsl = true,
};
}
public static void sendMail(string to, string subj, string body)
{
smtpClient.Send("noreply@bulletboards.xyz", to, subj, body);
smtpClient.Send(values["email-address"].ToString(), to, subj, body);
}
}