mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 23:49:02 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RadicadeServer.Radicade.Mail;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static class RadicadeMail
|
||||
{
|
||||
private static readonly HttpClient Http = new();
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
public static async Task SendAsync(string to, string subject, string html)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(DBConfig.MailApiKey)) return;
|
||||
if (string.IsNullOrWhiteSpace(to) || !to.Contains('@')) return;
|
||||
if (string.IsNullOrWhiteSpace(DBConfig.MailFrom)) return;
|
||||
try
|
||||
{
|
||||
var payload = new
|
||||
{
|
||||
from = $"{DBConfig.MailFromName} <{DBConfig.MailFrom}>",
|
||||
to = new[] { to },
|
||||
subject,
|
||||
html
|
||||
};
|
||||
|
||||
using var req = new HttpRequestMessage(HttpMethod.Post, DBConfig.MailApiUrl)
|
||||
{
|
||||
Headers = { Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", DBConfig.MailApiKey) },
|
||||
Content = new StringContent(JsonSerializer.Serialize(payload, JsonOptions), Encoding.UTF8, "application/json")
|
||||
};
|
||||
|
||||
using var res = await Http.SendAsync(req);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user