mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 11:21:47 -05:00
Report audit log when mail send completes.
This commit is contained in:
parent
3ddcf99fb6
commit
ad575bcd38
1 changed files with 16 additions and 2 deletions
|
@ -38,9 +38,23 @@ public Task SendAsync(IdentityMessage message)
|
|||
<p>" + CommonMark.CommonMarkConverter.Convert(message.Body) + "</p>";
|
||||
sMsg.Subject = $"[{siteConfig.SiteName}] " + message.Subject;
|
||||
sMsg.IsBodyHtml = true;
|
||||
smtp.SendAsync(sMsg, null);
|
||||
var db = new ApplicationDbContext();
|
||||
db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, $"Email sent successfully.<br/><br/><strong>To:</strong> {sMsg.To}<br/><strong>Subject:</strong><br/>{sMsg.Subject}"));
|
||||
db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, $"Email sending...<br/><br/><strong>To:</strong> {sMsg.To}<br/><strong>Subject:</strong><br/>{sMsg.Subject}"));
|
||||
db.SaveChanges();
|
||||
smtp.SendCompleted += (o, a) =>
|
||||
{
|
||||
var alog = new AuditLog("system", AuditLogLevel.Admin, "");
|
||||
if (a.Cancelled == true)
|
||||
alog.Description += "Send cancelled.<br/>";
|
||||
if (a.Error == null)
|
||||
alog.Description += "No errors detected.</br>";
|
||||
else
|
||||
alog.Description += $"Error:<br/><pre><code class=\"language-csharp\">{a.Error}</code></pre>";
|
||||
var ndb = new ApplicationDbContext();
|
||||
ndb.AuditLogs.Add(alog);
|
||||
ndb.SaveChanges();
|
||||
};
|
||||
smtp.SendAsync(sMsg, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue