Innovenergy_trunk/csharp/App/Backend/Mailer/Mailer.cs

44 lines
1.7 KiB
C#
Raw Normal View History

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 = "<Pending>")]
public static Boolean SendVerificationMessage (User emailRecipientUser)
{
var config = JsonSerializer.Deserialize<SmptConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
var email = new MimeMessage();
2023-04-06 12:28:35 +00:00
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);
2023-04-06 12:28:35 +00:00
smtp.Send(email);
smtp.Disconnect(true);
}
catch (Exception)
{
return false;
}
return true;
}
}