Setting up STMP email in web.config based on external source

74 views
Skip to first unread message

Nik

unread,
Aug 19, 2008, 10:45:52 PM8/19/08
to ELMAH
I am wondering if anyone has ever pulled in the configuration settings
for the SMTP email for ELMAH from an external source. It could be
from an XML file, method, or database.

I am wanting to implement a UI of some sort to allow an Admin to enter
in the SMTP server information, set up the default subject and
recipient. Then feed that to the web.config for for ELMAH to use.

Any suggests would be appreciated.

Thanks
Nik

Atif Aziz

unread,
Aug 20, 2008, 2:51:36 AM8/20/08
to el...@googlegroups.com
Nik,

>>
I am wondering if anyone has ever pulled in the configuration settings
for the SMTP email for ELMAH from an external source. It could be
from an XML file, method, or database.
<<

This is possible today by inheriting from ErrorMailModule and overriding its GetConfig method. Next, you register your derived module instead of the base one from ELMAH.

>>
I am wanting to implement a UI of some sort to allow an Admin to enter
in the SMTP server information, set up the default subject and
recipient. Then feed that to the web.config for for ELMAH to use.
<<

You could just -write the new settings to web.config and they'll be picked up on restart. The restart is important in order for the module to pick up the refreshed configuration since modules are initialized at application start-up time.

- Atif

Nik

unread,
Oct 12, 2008, 4:08:49 PM10/12/08
to ELMAH
I was able to move my config settings out of the web config file by
overrideing the GetConfig() method. After doing some testing, this
did't quite get me the result I was looking for.

The last piece I am looking for is a way for the Email module to look
at the config when a error occurs and and email is generated. That
way if the config settings are changed through the UI, the entire
application doesn't need to be restarted in order for the changes to
take effect.

It looks like the GetConfig happens during OnInit. Would it be
possible to move this call to someplace else in the module so it gets
called at runtime?

Thanks
Nik

On Aug 20, 1:51 am, Atif Aziz <Atif.A...@skybow.com> wrote:
> Nik,
>
>
>
> I am wondering if anyone has ever pulled in the configuration settings
> for the SMTPemailforELMAHfrom an external source.  It could be
> from an XML file, method, or database.
> <<
>
> This is possible today by inheriting from ErrorMailModule and overriding its GetConfig method. Next, you register your derived module instead of the base one fromELMAH.
>
>
>
> I am wanting to implement a UI of some sort to allow an Admin to enter
> in the SMTP server information, set up the default subject and
> recipient.  Then feed that to the web.config for forELMAHto use.
> <<
>
> You could just -write the new settings to web.config and they'll be picked up on restart. The restart is important in order for the module to pick up the refreshed configuration since modules are initialized at application start-up time.
>
> - Atif
>
>
>
> -----Original Message-----
> From:el...@googlegroups.com [mailto:el...@googlegroups.com] On Behalf Of Nik
> Sent: Wednesday, August 20, 2008 4:46 AM
> To:ELMAH
> Subject: [ELMAH] Setting up STMPemailin web.config based on external source
>
> I am wondering if anyone has ever pulled in the configuration settings
> for the SMTPemailforELMAHfrom an external source.  It could be
> from an XML file, method, or database.
>
> I am wanting to implement a UI of some sort to allow an Admin to enter
> in the SMTP server information, set up the default subject and
> recipient.  Then feed that to the web.config for forELMAHto use.
>
> Any suggests would be appreciated.
>
> Thanks
> Nik- Hide quoted text -
>
> - Show quoted text -

Nik

unread,
Nov 27, 2008, 10:38:56 AM11/27/08
to ELMAH
Has anyone successfully moved the reading of the email configuration
settings to happen during runtime instead of OnInit?

My scenario is that we have created a GUI to enter and save the Elmah
email config in a file. We would like to be able to make changes in
the GUI, save them, and have the changes used right away without
having to restart the entire web application.

Thanks in advance
Nik

Atif Aziz

unread,
Nov 27, 2008, 11:04:33 AM11/27/08
to el...@googlegroups.com
A solution was already posted earlier:
http://groups.google.com/group/elmah/msg/e465a6a5486d9cf6

If you don't modifying Global.asax then a simpler solution would be to simply trap the Mailing event raised by the standard ErrorMailModule before the mail is sent out. In the arguments to the event, you get a chance to manipulate the MailMessage object and you could replace to "To" address by reading it out of your own configuration location.
Reply all
Reply to author
Forward
0 new messages