Exception Emails are not sent in asp.net core 3.1 razor pages
fingers10 opened this issue · 1 comments
fingers10 commented
I'm configuring exceptional email options in my asp.net core 3.1 app. But doesn't seem to work.
here is my start up,
services.AddExceptional(settings =>
{
settings.Store.ApplicationName = "Exceptional.Web";
settings.Store.Type = "SQL";
settings.Store.ConnectionString = "Server=(localdb)\\mssqllocaldb;Database=ExceptionalDemos;Trusted_Connection=True;MultipleActiveResultSets=true";
settings.UseExceptionalPageOnThrow = false;
settings.Email.ToAddress = "xxxx@gmail.com";
settings.Email.FromAddress = "xxxx@xxxx.com";
settings.Email.FromDisplayName = "xxxx@xxxx.com";
settings.Email.SMTPHost = "xxxx.xxxx.net";
settings.Email.SMTPPort = 0000;
settings.Email.SMTPUserName = "xxxx@xxxx.com";
settings.Email.SMTPPassword = "xxxx";
settings.Email.SMTPEnableSSL = true;
});
I'm using the same to send email in my app and it works,
using (var smtp = new SmtpClient("xxxx.xxxx.net", 0000))
{
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
NetworkCredential credentials = new NetworkCredential("xxxx@xxxx.com", "xxxx");
smtp.Credentials = credentials;
var msg = new MailMessage
{
Body = "Error From App",
Subject = "Error Test",
From = new MailAddress("xxxx@xxxx.com")
};
msg.To.Add("xxxx@gmail.com");
await smtp.SendMailAsync(msg);
}
I not able to find out any error messages logged in console. Any ideas on why the exception emails are not getting sent?
NickCraver commented
Ah, we create this in the bind case (loading config from a file, etc.) but not in code. You could currently manually add it via:
settings.Register(new EmailNotifier(settings.Email));
...but yes, should re-visit how this behaves for code configuration.
Overall, your code can look something like this:
services.AddExceptional(settings =>
{
settings.Store.ApplicationName = "Exceptional.Web";
settings.Store.Type = "SQL";
settings.Store.ConnectionString = "Server=(localdb)\\mssqllocaldb;Database=ExceptionalDemos;Trusted_Connection=True;MultipleActiveResultSets=true";
settings.UseExceptionalPageOnThrow = false;
settings.Register(new EmailNotifier(new EmailSettings()
{
ToAddress = "xxxx@gmail.com",
FromAddress = "xxxx@xxxx.com",
FromDisplayName = "xxxx@xxxx.com",
SMTPHost = "xxxx.xxxx.net",
SMTPPort = 0000,
SMTPUserName = "xxxx@xxxx.com",
SMTPPassword = "xxxx",
SMTPEnableSSL = true
}));
});