从ELMAH发送电子邮件? [英] Send email from Elmah?

查看:239
本文介绍了从ELMAH发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时使用ELMAH通过电子邮件发送异常的人?我有ELMAH记录通过SQL Server的设置,并且可以通过Elmah.axd页面显示出错页面,但我无法得到电子邮件组件工作。这里的想法是获得电子邮件通知,所以我们可以更迅速地对异常反应。这里是我的web.config(不必要的sectionss略),与* * *代替所有的敏感数据。即使我指定要连接的服务器,并SMTP服务需要在本地机器上运行?

 < XML版本=1.0&GT?;
<结构>
    < configSections>
        < sectionGroup名=ELMAH>
            <节名称=错误日志requirePermission =假TYPE =Elmah.ErrorLogSectionHandler,ELMAH/>
            <节名称=errorMailrequirePermission =假TYPE =Elmah.ErrorMailSectionHandler,ELMAH/>
            <节名称=errorFilterrequirePermission =假TYPE =Elmah.ErrorFilterSectionHandler,ELMAH/>
        < / sectionGroup>
    < / configSections>
    <的appSettings />
    <的ConnectionStrings>
        <添加名称=ELMAH-SQL的connectionString =数据源= ***;初始目录= ***;坚持安全信息= TRUE;用户ID = ***;密码= ***/>
    < /的ConnectionStrings>

    < ELMAH>
        <错误日志型=Elmah.SqlErrorLog,ELMAH的connectionStringName =ELMAH-SQL>
        < /错误日志>
        < errorMail来自=test@test.com
           为=test@test.com
           主题=应用程序异常
           异步=假
           SMTPPORT =25
           SMTPSERVER =***
           USERNAME =***
           密码=***>
        < / errorMail>
    < / ELMAH>

    <的System.Web>
        <的customErrors模式=仅限远程的defaultRedirect =CustomError.aspx>
            <错误状态code =403重定向=NotAuthorized.aspx/>
            <! - <错误状态code =404重定向=FileNotFound.htm/>  - >
        < /的customErrors>
    < HttpHandlers的>
    <删除动词=*路径=* ASMX。/>
    <加上动词=*路径=*。ASMX验证=假TYPE =System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <加上动词=*路径=* _ AppService.axd验证=假TYPE =System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions程序,版本= 3.5.0.0,文化=中立,公钥= 31BF3856AD364E35/>
    <加上动词=GET,HEAD路径=的ScriptResource.axdTYPE =System.Web.Handlers.ScriptResourceHandler,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35验证= 假/>
            <加上动词=POST,GET,HEAD路径=elmah.axdTYPE =Elmah.ErrorLogPageFactory,ELMAH/>
        < / HttpHandlers的>
    <的HttpModules>
    <添加名称=ScriptModuleTYPE =System.Web.Handlers.ScriptModule,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
            <添加名称=错误日志TYPE =Elmah.ErrorLogModule,ELMAH/>
        < / HttpModules的>
    < /system.web>

< /结构>
 

解决方案

您需要ErrorMail HTTP模块。

添加此行的&lt内,的HttpModules>部分

 <添加名称=ErrorMailTYPE =Elmah.ErrorMailModule,ELMAH/>
 

如果您使用的是远程SMTP服务器(它看起来像你),你没有在服务器上需要SMTP。

Is anyone using Elmah to send exceptions via email? I've got Elmah logging set up via SQL Server, and can view the errors page via the Elmah.axd page, but I am unable to get the email component working. The idea here is to get the email notification so we can react more quickly to exceptions. Here is my web.config (unnecessary sectionss omitted), with all the sensitive data replaced by * * *. Even though I am specifying a server to connect to, does the SMTP service need to be running on the local machine?

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="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/>
    <connectionStrings>
        <add name="elmah-sql" connectionString="Data Source=***;Initial Catalog=***;Persist Security Info=True;User ID=***;Password=***" />
    </connectionStrings>

    <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="25"
           smtpServer="***"
           userName="***"
           password="***">
        </errorMail>
    </elmah>

    <system.web>        
        <customErrors mode="RemoteOnly" defaultRedirect="CustomError.aspx">
            <error statusCode="403" redirect="NotAuthorized.aspx" />
            <!--<error statusCode="404" redirect="FileNotFound.htm" />-->
        </customErrors>
    	<httpHandlers>
    		<remove verb="*" path="*.asmx"/>
    		<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
            <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
        </httpHandlers>
    	<httpModules>
    		<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        </httpModules>
    </system.web>

</configuration>

解决方案

You need the ErrorMail httpModule.

add this line inside the <httpModules> section

<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />

If you're using a remote SMTP server (which it looks like you are) you don't need SMTP on the server.

这篇关于从ELMAH发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆