How can I connect my own email provider in ELMAH?

I asked about this in the elmah group in google groups, but am still puzzled, so I decided that I would throw him in a larger pool. Here's the original note with my code that is currently worth it.


I have ELMAH installed in my MVC 5 application and I want to use a dedicated email service to send email instead of using smtp sending, which is configured by default. (This is organizational preference.) I have already been picking it, but I can’t figure out how to do it. My service call works fine, but I can’t connect it so that it works when there is an exception. Any help would be greatly appreciated.

What I set up is this:

Web.config (deleted lines not related to elmah):

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <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" />
    </sectionGroup>
  </configSections><appSettings>
    ...
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
    <add key="elmah.mvc.requiresAuthentication" value="false" />
    <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
    <add key="elmah.mvc.allowedRoles" value="*" />
    <add key="elmah.mvc.allowedUsers" value="*" />
    <add key="elmah.mvc.route" value="elmah" />
</appSettings>
  <connectionStrings>
    <add name="BFRDPDB" providerName="System.Data.SqlClient" connectionString="blahblah;" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <customErrors mode="Off" defaultRedirect="~/Home/Error">
      <error statusCode="404" redirect="~/Home/Error" />
    </customErrors>
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="BFRDP.Infrastructure.ErrorMailModule" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="BFRDP.Infrastructure.ErrorMailModule" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  <elmah>
    <security allowRemoteAccess="false" />
    <errorLog type="Elmah.SqlErrorLog, Elmah"
              connectionStringName="BFRDPDB"
              applicationName="FarmAnswers.org" /> 
  </elmah>
  <location path="elmah">
    <system.web>
      <httpHandlers>
        <add verb="POST,GET,HEAD"
             path="elmah.axd"
             type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>
      <authorization>
        <allow roles="SuperAdmin" />
        <deny users="*" />
      </authorization>
    </system.web>
    <system.webServer>
      <handlers>
        <add name="ELMAH"
             verb="POST,GET,HEAD"
             path="elmah"
             type="Elmah.ErrorLogPageFactory, Elmah"
             preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>
</configuration>

ErrorMailModule.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;

namespace BFRDP.Infrastructure
{/// <summary>
    /// Summary description for ErrorMailModule
    /// </summary>
    public class ErrorMailModule : Elmah.ErrorMailModule
    {
        public ErrorMailModule()
        {
        }



        protected override void SendMail(MailMessage mail)
        {
            if (mail == null)
                throw new ArgumentNullException("mail");
            // Code to send email here through internal provider
        }

    }
}

, .

?

+4
1

errorMail web.config, :

  <elmah>
    <security allowRemoteAccess="false" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="BFRDPDB" applicationName="FarmAnswers.org" />
    <errorMail
    from="elmah@example.com"
    to="admin@example.com"
    subject="..."
    priority="Low"
    async="true"
    smtpPort="25"
    smtpServer="smtp.example.com"
    useSsl="true"
    userName="johndoe"
    password="secret"
    noYsod="true" />
  </elmah>
+3

All Articles