无法从ELMAH发送我的asp.net mvc应用程序的电子邮件

时间:2014-03-28 08:13:40

标签: elmah.mvc

我无法从ELMAH发送邮件给我的asp.net mvc应用程序。

我遇到了异常。

  

发生了'System.Net.Mail.SmtpException'类型的异常   System.dll但未在用户代码中处理

表示我的凭据不正确,但它是正确的,因为我能够发送电子邮件 使用 MailMessage

的代码

以下是我对ELMAH的web.config文件设置。

<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>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

在&#34; system.net&#34;中配置邮件设置。 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>

加入&#34; elmah&#34;部分:

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