2023-03-23 12:37:35 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2023-03-23 11:47:25 +00:00
|
|
|
using InnovEnergy.App.Backend.DataTypes;
|
|
|
|
using MailKit.Net.Smtp;
|
|
|
|
using MimeKit;
|
2023-03-23 12:37:35 +00:00
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
2023-03-23 11:47:25 +00:00
|
|
|
|
|
|
|
namespace InnovEnergy.App.Backend.Mailer;
|
|
|
|
public static class Mailer
|
|
|
|
{
|
2023-03-23 12:37:35 +00:00
|
|
|
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
|
|
|
public static Boolean SendVerificationMessage (User emailRecipientUser)
|
2023-03-23 11:47:25 +00:00
|
|
|
{
|
2023-03-23 12:37:35 +00:00
|
|
|
var config = JsonSerializer.Deserialize<SmptConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
|
2023-03-23 11:47:25 +00:00
|
|
|
var email = new MimeMessage();
|
|
|
|
|
2023-04-06 12:28:35 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2023-03-23 11:47:25 +00:00
|
|
|
email.From.Add(new MailboxAddress("InnovEnergy", "noreply@innov.energy"));
|
2023-03-23 13:23:03 +00:00
|
|
|
email.To.Add(new MailboxAddress(emailRecipientUser.Name, emailRecipientUser.Email));
|
2023-03-23 11:47:25 +00:00
|
|
|
|
|
|
|
email.Subject = "Create a new password for your Innovenergy-Account";
|
|
|
|
email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) {
|
|
|
|
Text = "Dear " + emailRecipientUser.Name + "\n Please create a new password for your Innovenergy-account." +
|
|
|
|
"\n To do this just login at https://HEEEEELP"
|
|
|
|
};
|
2023-03-23 13:23:03 +00:00
|
|
|
|
|
|
|
using var smtp = new SmtpClient();
|
|
|
|
smtp.Connect(config.Url, config.Port, false);
|
2023-03-23 11:47:25 +00:00
|
|
|
|
2023-03-23 13:23:03 +00:00
|
|
|
smtp.Authenticate(config.Username, config.Password);
|
2023-03-23 11:47:25 +00:00
|
|
|
|
2023-04-06 12:28:35 +00:00
|
|
|
smtp.Send(email);
|
|
|
|
smtp.Disconnect(true);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-23 11:47:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|