diff --git a/Project-Unite/App_Start/IdentityConfig.cs b/Project-Unite/App_Start/IdentityConfig.cs index db5889a..b9ca64b 100644 --- a/Project-Unite/App_Start/IdentityConfig.cs +++ b/Project-Unite/App_Start/IdentityConfig.cs @@ -18,45 +18,30 @@ namespace Project_Unite { public class EmailService : IIdentityMessageService { - public async Task SendAsync(IdentityMessage message) + public async Task SendAsync(IdentityMessage msg) { try { var siteConfig = new ApplicationDbContext().Configs.FirstOrDefault(); + var message = new MailMessage(); + message.To.Add(new MailAddress(msg.Destination)); + message.Subject = "[ShiftOS] " + msg.Subject; + message.Body = msg.Body; + message.IsBodyHtml = true; - var smtp = new SmtpClient(siteConfig.SMTPServer, siteConfig.SMTPPort); - smtp.UseDefaultCredentials = false; - if (siteConfig.UseTLSEncryption) - smtp.EnableSsl = true; //This is misleading... We want TLS but all we have is SSL. Oh well. - smtp.UseDefaultCredentials = false; - smtp.Credentials = new NetworkCredential(siteConfig.SMTPUsername, siteConfig.SMTPPassword); - var sMsg = new MailMessage(siteConfig.SMTPReturnAddress, message.Destination); - - sMsg.Body = @" - -
" + CommonMark.CommonMarkConverter.Convert(message.Body) + "
"; - sMsg.Subject = $"[{siteConfig.SiteName}] " + message.Subject; - sMsg.IsBodyHtml = true; - smtp.DeliveryMethod = SmtpDeliveryMethod.Network; - var db = new ApplicationDbContext(); - db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, $"Email sending...{a.Error}
";
- var ndb = new ApplicationDbContext();
- ndb.AuditLogs.Add(alog);
- await ndb.SaveChangesAsync();
- };
- smtp.Send(sMsg);
+ var credential = new NetworkCredential
+ {
+ UserName = siteConfig.SMTPUsername,
+ Password = siteConfig.SMTPPassword
+ };
+ smtp.Credentials = credential;
+ smtp.Host = siteConfig.SMTPServer;
+ smtp.Port = siteConfig.SMTPPort;
+ smtp.EnableSsl = siteConfig.UseTLSEncryption;
+ await smtp.SendMailAsync(message);
+ }
}
catch (Exception ex)
{