using System.Diagnostics.CodeAnalysis; using InnovEnergy.App.Backend.DataTypes; using MailKit.Net.Smtp; using MimeKit; using JsonSerializer = System.Text.Json.JsonSerializer; namespace InnovEnergy.App.Backend.Mailer; public static class Mailer { [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "")] public static Boolean SendVerificationMessage (User emailRecipientUser) { var config = JsonSerializer.Deserialize(File.OpenRead("./Resources/smtpConfig.json"))!; var email = new MimeMessage(); try { email.From.Add(new MailboxAddress("InnovEnergy", "noreply@innov.energy")); email.To.Add(new MailboxAddress(emailRecipientUser.Name, emailRecipientUser.Email)); 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" }; using var smtp = new SmtpClient(); smtp.Connect(config.Url, config.Port, false); smtp.Authenticate(config.Username, config.Password); smtp.Send(email); smtp.Disconnect(true); } catch (Exception) { return false; } return true; } }