Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Emails are not sent in asp.net core 3.1 razor pages #183

Open
fingers10 opened this issue Mar 19, 2020 · 1 comment
Open

Exception Emails are not sent in asp.net core 3.1 razor pages #183

fingers10 opened this issue Mar 19, 2020 · 1 comment

Comments

@fingers10
Copy link

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 = "[email protected]";
    settings.Email.FromAddress = "[email protected]";
    settings.Email.FromDisplayName = "[email protected]";
    settings.Email.SMTPHost = "xxxx.xxxx.net";
    settings.Email.SMTPPort = 0000;
    settings.Email.SMTPUserName = "[email protected]";
    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("[email protected]", "xxxx");
    smtp.Credentials = credentials;
    var msg = new MailMessage
    {
        Body = "Error From App",
        Subject = "Error Test",
        From = new MailAddress("[email protected]")
    };
    msg.To.Add("[email protected]");
    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
Copy link
Owner

NickCraver commented Jul 25, 2021

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 = "[email protected]",
	      FromAddress = "[email protected]",
	      FromDisplayName = "[email protected]",
	      SMTPHost = "xxxx.xxxx.net",
	      SMTPPort = 0000,
	      SMTPUserName = "[email protected]",
	      SMTPPassword = "xxxx",
	      SMTPEnableSSL = true
	}));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants