Elmah does not work with gmail for MVC 3

I am using ELMAH for my MVC 3 application with Gmail. I used a few links on how to do this, including https://stackoverflow.com/a/167189/ which has several fixes

I still cannot determine why I do not receive emails from elmah. I am trying to check this by throwing a NullReferenceException in my code that I am calling.

My web.config looks like this:

<configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> <sectionGroup name="elmah"> <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/> <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/> <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/> <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> </namespaces> </pages> </system.web.webPages.razor> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <httpHandlers> <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> </httpHandlers> <httpModules> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> </httpModules> <!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller. By default MVC performs request validation before a controller processes the input. To change this behavior apply the ValidateInputAttribute to a controller or action. --> <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <controls> <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> </system.web> <system.net> <mailSettings> <smtp deliveryMethod="Network"> <network host="smtp.gmail.com" port="587" userName=" username@gmail.com " password="myPassword"/> </smtp> </mailSettings> </system.net> <elmah> <errorMail from=" fromAddress@gmail.com " to=" toAddress@gmail.com " subject="Error" async="true" smtpPort="587" useSsl="true"/> </elmah> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> </handlers> <modules runAllManagedModulesForAllRequests="true"> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> </modules> </system.webServer> </configuration> 

Any ideas on why this might not work?

+4
source share
1 answer

EDIT: This may not necessarily be true when looking at other ELMAH configurations, but you can try this anyway. In addition, I know that the enableSSL attribute in the settings of the system.net mail system is new in .NET 4.0 - you may need to add enableSSL=true in this section, since GMail uses SSL to connect.

It looks like you left the host configuration property and a few other settings from the ELMAH email settings when comparing your setup with the settings of other ELMAH configurations. I do not think ELMAH looks at the settings of the system.net mail system, but rather has its own errorMail tag

It:

 <elmah> <errorMail from=" fromAddress@gmail.com " to=" toAddress@gmail.com " subject="Error" async="true" smtpPort="587" useSsl="true"/> </elmah> 

Change to this:

 <elmah> <errorMail from=" fromAddress@gmail.com " to=" toAddress@gmail.com " subject="Error" async="true" smtpPort="587" useSsl="true" host="smtp.gmail.com" userName=" username@gmail.com " password="myPassword"/> </elmah> 
+8
source

All Articles