added smtpconfig class and put smtp config data into resources json file
This commit is contained in:
parent
432189f461
commit
7c385bc51c
|
@ -1,16 +1,20 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using InnovEnergy.App.Backend.DataTypes;
|
using InnovEnergy.App.Backend.DataTypes;
|
||||||
using MailKit.Net.Smtp;
|
using MailKit.Net.Smtp;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend.Mailer;
|
namespace InnovEnergy.App.Backend.Mailer;
|
||||||
public static class Mailer
|
public static class Mailer
|
||||||
{
|
{
|
||||||
public static Boolean SendVerificationMessage (User emailRecipientUser)
|
[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();
|
var email = new MimeMessage();
|
||||||
|
|
||||||
email.From.Add(new MailboxAddress("InnovEnergy", "noreply@innov.energy"));
|
email.From.Add(new MailboxAddress("InnovEnergy", "noreply@innov.energy"));
|
||||||
email.To.Add(new MailboxAddress(emailRecipientUser.Name, "fern95@ethereal.email"));
|
email.To.Add(new MailboxAddress(emailRecipientUser.Name, "fern95@ethereal.email")); //TODO CHANGE ME
|
||||||
|
|
||||||
email.Subject = "Create a new password for your Innovenergy-Account";
|
email.Subject = "Create a new password for your Innovenergy-Account";
|
||||||
email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) {
|
email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) {
|
||||||
|
@ -19,10 +23,10 @@ public static class Mailer
|
||||||
};
|
};
|
||||||
using (var smtp = new SmtpClient())
|
using (var smtp = new SmtpClient())
|
||||||
{
|
{
|
||||||
smtp.Connect("smtp.ethereal.email", 587, false);
|
smtp.Connect(config.Url, config.Port, false);
|
||||||
|
|
||||||
// Todo put me into urlAndKey.json
|
// Todo put me into urlAndKey.json
|
||||||
smtp.Authenticate("fern95@ethereal.email", "dYKVnc4RQNEFckHaNV");
|
smtp.Authenticate(config.Username, config.Password);
|
||||||
|
|
||||||
smtp.Send(email);
|
smtp.Send(email);
|
||||||
smtp.Disconnect(true);
|
smtp.Disconnect(true);
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
namespace InnovEnergy.App.Backend.Mailer;
|
||||||
|
|
||||||
|
public class SmptConfig
|
||||||
|
{
|
||||||
|
public String Url { get; init; }
|
||||||
|
public String Username { get; init; }
|
||||||
|
public String Password { get; init; }
|
||||||
|
public Int32 Port { get; init; }
|
||||||
|
|
||||||
|
public SmptConfig()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"Url": "smtp.ethereal.email",
|
||||||
|
"Port": 587,
|
||||||
|
"Username": "fern95@ethereal.email",
|
||||||
|
"Password": "dYKVnc4RQNEFckHaNV"
|
||||||
|
}
|
Loading…
Reference in New Issue