2023-09-15 14:30:41 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using InnovEnergy.App.Backend.DataTypes;
|
|
|
|
using InnovEnergy.Lib.Mailer;
|
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
|
|
|
|
namespace InnovEnergy.App.Backend.Email;
|
|
|
|
public static class Email
|
|
|
|
{
|
|
|
|
[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)
|
|
|
|
{
|
|
|
|
var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
|
|
|
|
var mailer = new Mailer();
|
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
mailer.From("InnovEnergy", "noreply@innov.energy");
|
|
|
|
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
|
2023-09-15 14:30:41 +00:00
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
mailer.Subject("Create a new password for your Innovenergy-Account");
|
|
|
|
mailer.Body("Dear " + emailRecipientUser.Name +
|
2023-09-15 14:30:41 +00:00
|
|
|
"\n Please create a new password for your Innovenergy-account." +
|
|
|
|
"\n To do this just login at https://HEEEEELP");
|
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
return mailer.SendEmailUsingSmtpConfig(config);
|
2023-09-15 14:30:41 +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 SendPasswordResetMessage (User emailRecipientUser, String token)
|
|
|
|
{
|
|
|
|
var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
|
|
|
|
|
|
|
|
//todo am I right?
|
2023-09-15 14:39:01 +00:00
|
|
|
const String resetLink = "https://monitor.innov.energy/api/ResetPassword";
|
2023-09-15 14:59:59 +00:00
|
|
|
var mailer = new Mailer();
|
2023-09-15 14:30:41 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
mailer.From("InnovEnergy", "noreply@innov.energy");
|
|
|
|
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
|
2023-09-15 14:30:41 +00:00
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
mailer.Subject("Reset the password of your Innovenergy-Account");
|
|
|
|
mailer.Body("Dear " + emailRecipientUser.Name
|
2023-09-15 14:30:41 +00:00
|
|
|
+ "\n To reset your password open this link:"
|
2023-09-15 14:45:00 +00:00
|
|
|
+ resetLink + "?token="
|
2023-09-15 14:30:41 +00:00
|
|
|
+ token);
|
|
|
|
|
2023-09-15 14:59:59 +00:00
|
|
|
return mailer.SendEmailUsingSmtpConfig(config);
|
2023-09-15 14:30:41 +00:00
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|