0

I could not able to send mail from ELMAH for my asp.net mvc application.

I am getting following exception.

An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code

which says my credentials are incorrect but it is correct because I am able to send email by code using MailMessage class

Following is my web.config file settings for ELMAH.

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
    <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
  </system.web>

<system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
      <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" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>


        <elmah>

        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql"></errorLog>

        <errorMail from="test@test.com"
               to="test@test.com"
               subject="Application Exception"
               async="false"
               smtpPort="587"
               smtpServer="smtp.office365.com"
               userName="test@test.com"
                   enableSsl="true"
               password="Dacu46361!">
        </errorMail>

        <security allowRemoteAccess="1" />
      </elmah>

    <location path="elmah.axd" inheritInChildApplications="false">
        <system.web>
          <httpModules>
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
          </httpModules>
          <httpHandlers>
            <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
          </httpHandlers>

        </system.web>
        <system.webServer>
          <handlers>
            <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
          </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>
      </location>

Thanks for help in advance.

Shaishav7
  • 139
  • 1
  • 11

1 Answers1

2

Configure mail settings in "system.net" section in web.config:

  <system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="origin@domain.com">
            <network host="smtp.office365.com" enableSsl="true" port="587" userName="XXX" password="XXX"/>
        </smtp>
    </mailSettings>
  </system.net>

Include in "elmah" section:

<errorMail from="origin@domain.com" to="target@domain.com" subject="Error in my domain.com" async="true" useSsl="true" />
jiman14
  • 51
  • 3