Sending Error Mail from Elmah

As part of a recent release of a web application we decided that in order to make the best use of error logs being created by Elmah we should email these to stakeholders as and when they happen to improve the general response times. Here is how we set up ‘that thing’ in our .NET MVC4 application! The red sections indicate properties that were either added or edited to enable the email functionality and green section indicate those fields you will need to change to reflect your choice of smtp server.

<?xml version="1.0" encoding="utf-8"?>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        <sessionState timeout="20" mode="InProc" customProvider="DefaultSessionProvider">
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        <validation validateIntegratedModeConfiguration="false" />
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
        <errorMail from="" to="" async="true" smtpPort="0" useSsl="true" />
        <security allowRemoteAccess="false" />
            <smtp deliveryMethod ="Network"> 
            <network host="" port="587" userName="gmailuserName"   password="gmailPassword" /> 
    <location path="elmah.axd" inheritInChildApplications="false">

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s