me traigo todos los cambios del recuperar cuenta y set email respaldo
This commit is contained in:
50
Aspnet/Emailer/Decorator/EmailerSender.cs
Normal file
50
Aspnet/Emailer/Decorator/EmailerSender.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AlquilaFacil.Emailer.Sender;
|
||||
|
||||
public class EmailSender
|
||||
{
|
||||
protected static SmtpClient? smtp = null;
|
||||
protected void configSmtp(MailMessage mail)
|
||||
{
|
||||
var jsonContent = File.ReadAllText("settings.json");
|
||||
var options = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonContent);
|
||||
if (options == null) return;
|
||||
|
||||
|
||||
bool check = options.ContainsKey("smtpHost");
|
||||
check = options.ContainsKey("smtpPort");
|
||||
check = options.ContainsKey("emailAddr");
|
||||
check = options.ContainsKey("emailPass");
|
||||
|
||||
if (check == false) return;
|
||||
mail.Sender = new MailAddress(options["emailAddr"]);
|
||||
mail.From = new MailAddress(options["emailAddr"]);
|
||||
|
||||
if (null != smtp) return;
|
||||
smtp = new();
|
||||
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
smtp.EnableSsl = true;
|
||||
smtp.Host = options["smtpHost"];
|
||||
smtp.Port = int.Parse(options["smtpPort"].ToString());
|
||||
smtp.Credentials = new NetworkCredential(options["emailAddr"], options["emailPass"]);
|
||||
}
|
||||
|
||||
public virtual void Send(MailMessage message)
|
||||
{
|
||||
configSmtp(message);
|
||||
if (smtp == null) return;
|
||||
try
|
||||
{
|
||||
smtp.Send(message);
|
||||
message.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user