【问题标题】:Unable to configure mail for Elmah无法为 Elmah 配置邮件
【发布时间】:2011-12-17 03:17:38
【问题描述】:

我有如下配置文件sn -p

<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>
 <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com"
           port="587"
           userName="example@gmail.com"
           password="password" />
        </smtp>
      </mailSettings>
  </system.net>
 <elmah>
    <errorMail
              from="example1@gmail.com"
              to="example2@gmail.com"
              sync="true"
              smtpPort="0"
              useSsl="true"
            />
  </elmah>

我已经用适当的东西替换了 example1 等。现在,我有以下问题: - 1)为什么它不工作? 2)我如何调试它? 3)我需要一种永久的方式来调试 web.config 或至少一些代码,当配置文件出现问题时会发出一些错误消息。

【问题讨论】:

    标签: asp.net elmah


    【解决方案1】:

    试试这个:

    <?xml version="1.0"?>
    <configuration>
        <configSections>
            <!--ELMAH-->
            <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>
        <elmah>
            <security allowRemoteAccess="1"/>   
            <!-- set the smtpPort attribute to "0". Doing so will cause ELMAH to use the port defined per the <system.net> settings -->
            <errorMail from="example1@gmail.com" to="example2@gmail.com" subject="ERROR(test):" async="false" smtpPort="0" useSsl="true" />
        </elmah>
        <!--System.net Mail setup-->
        <system.net>
            <mailSettings>
                <smtp deliveryMethod="network">
                    <network host="smtp.gmail.com" port="587" userName="example1@gmail.com" password="..." />
                </smtp>
            </mailSettings>
        </system.net>
        <appSettings>
        ...
     </appSettings>
        <connectionStrings>
            ...     
        </connectionStrings>
        <system.web>
            <compilation debug="true">
                <assemblies>
                    ...
            </compilation>
            <customErrors mode="Off"/>
            ...
            <httpHandlers>
                ...
                <!--ELMAH-->
                <add verb="POST,GET,HEAD" path="MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>            
            </httpHandlers>
            <httpModules>
                ...
                <!-- ELMAH: Logging module -->
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
                <!-- <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> -->
                <!--<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>-->
            </httpModules>
            <httpRuntime maxRequestLength="458292"/>
            <authentication mode="Forms">
                ...
            </authentication>
        ...
        </system.web>
        <location path="MyErrorPage.aspx">
            <system.web>
                <authorization>
                    <allow users="?"/>
                </authorization>
            </system.web>
        </location> 
        <!-- 
            The system.webServer section is required for running ASP.NET AJAX under Internet
            Information Services 7.0.  It is not necessary for previous version of IIS.
        -->
        <system.webServer>
            <validation validateIntegratedModeConfiguration="false"/>
            <modules runAllManagedModulesForAllRequests="true">
                ...
                <!-- ELMAH-->
                <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> 
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
                <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
            </modules>
            <handlers>
                ...
                <!--ELMAH-->
                <add name="Elmah" verb="POST,GET,HEAD" path="MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>           
            </handlers>
        </system.webServer>
        <runtime>       
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                ...
            </assemblyBinding>
        </runtime>
        <location path="MyErrorPage/elmah.axd">
            <system.web>
          <authorization>
            <deny users="?"/>
            <allow users="?"/>
          </authorization>
            </system.web>
        </location>  
    </configuration>
    

    【讨论】:

      【解决方案2】:

      试试这个方法

      <system.net>
          <mailSettings>
            <smtp deliveryMethod="Network">
              <network host="smtp.gmail.com" defaultCredentials="false"
              port="587" userName ="yourMailId@gmail.com" password="yourMailPassword" />
            </smtp>
          </mailSettings>
         </system.net>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-14
        • 2010-12-14
        • 2015-08-12
        • 2016-11-24
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        相关资源
        最近更新 更多