Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize SMTP settings for ELMAH through code

Tags:

elmah

The application includes:

  • ASP .NET MVC web app
  • DAL
  • Background Service
  • Library project

The web app and background service projects use the library project to send emails. SMTP settings are included in a config file in the library project itself.

In this scenario, is there a way to bind ELMAH to pick up SMTP settings from the library project? Perhaps if there's a way to configure ELMAH through code (during Application_Start), it would help achieve what's intended.

Guidance much appreciated.

like image 533
Sameet Avatar asked Aug 17 '12 14:08

Sameet


2 Answers

You might find some use out of [this article].

Particularly the section about sending error reports automatically through email might be useful for you. Here's a more focused link with the same topic: [link]

Although these show how to setup a static address for your SMTP settings, I'm not sure I know how to dynamically create them at run-time based on a config file. If I find a way to do this in a better way I'll be sure to edit this answer or post a comment, but take a look at the links to see if they help for now.

like image 157
Joseph Lormand Avatar answered Nov 02 '22 06:11

Joseph Lormand


You can configure elmah to post the error report to an HTML address. See this article.

When you set it to post to that address, you can have whatever back end you want catch it and send the email for you.

You mentioned you're using MVC, so you could have elmah post to a controller action that would then send the email, using the SMTP settings from your library project since you'd have access to the references there.

like image 33
Mark Oreta Avatar answered Nov 02 '22 07:11

Mark Oreta