Innovenergy_trunk/csharp/App/Backend/Email/Email.cs

84 lines
3.7 KiB
C#

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();
mailer.From("InnovEnergy", "noreply@innov.energy");
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
mailer.Subject("Create a new password for your Innovenergy-Account");
mailer.Body("Dear " + emailRecipientUser.Name +
"\n Please create a new password for your Innovenergy-account." +
"\n To do this just login at https://HEEEEELP");
return mailer.SendEmailUsingSmtpConfig(config);
}
[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?
const String resetLink = "https://monitor.innov.energy/api/ResetPassword";
var mailer = new Mailer();
try
{
mailer.From("InnovEnergy", "noreply@innov.energy");
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
mailer.Subject("Reset the password of your Innovenergy-Account");
mailer.Body("Dear " + emailRecipientUser.Name
+ "\n To reset your password open this link:"
+ resetLink + "?token="
+ token);
return mailer.SendEmailUsingSmtpConfig(config);
}
catch (Exception)
{
return false;
}
}
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
public static Boolean SendNewUserMessage (User emailRecipientUser)
{
var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
//todo am I right?
var resetLink = $"https://monitor.innov.energy/?username={emailRecipientUser.Email}";
var mailer = new Mailer();
try
{
mailer.From("InnovEnergy", "noreply@innov.energy");
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
mailer.Subject("Your new Innovenergy-Account");
mailer.Body("Dear " + emailRecipientUser.Name
+ "\n To set your password and log in to your Innovenergy-Account open this link:"
+ resetLink);
return mailer.SendEmailUsingSmtpConfig(config);
}
catch (Exception)
{
return false;
}
}
}