developer tip

Elmah에서 이메일을 보내시겠습니까?

optionbox 2020. 9. 12. 09:48
반응형

Elmah에서 이메일을 보내시겠습니까?


Elmah를 사용하여 이메일을 통해 예외를 보내는 사람이 있습니까? SQL Server를 통해 Elmah 로깅을 설정했으며 Elmah.axd 페이지를 통해 오류 페이지를 볼 수 있지만 이메일 구성 요소를 작동시킬 수 없습니다. 여기서 아이디어는 예외에 더 빨리 대응할 수 있도록 이메일 알림을받는 것입니다. 다음은 내 web.config (불필요한 섹션 생략)이며 모든 민감한 데이터가 * * *로 대체되었습니다. 연결할 서버를 지정하고 있는데 SMTP 서비스가 로컬 컴퓨터에서 실행되고 있어야합니까?

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

ErrorMail httpModule이 필요합니다.

<httpModules> 섹션 안에이 줄을 추가합니다.

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

원격 SMTP 서버를 사용하는 경우 (현재처럼 보이는) 서버에 SMTP가 필요하지 않습니다.


Yes, if you are not using remote SMTP server you must have SMTP Server configured locally. You can also configure email for elmah in web.config as follows:

<configSections>
   <sectionGroup name="elmah">
     <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler,  Elmah"> 
    </sectionGroup>
</configSections> 

<elmah> 
     <errorMail from="from Mail Address" to="to mail address" 
                async="true"  smtpPort="0" useSsl="true" /> 
</elmah>

<system.net> 
    <mailSettings> 
      <smtp deliveryMethod ="Network"> 
        <network host="smtp.gmail.com" port="587" userName="yourgmailEmailAddress"   password="yourGmailEmailPassword" /> 
      </smtp> 
    </mailSettings> 
</system.net>

I have used Elmah myself in this configuration and I had to setup the server with SMTP locally. It is a straight-forward install on you local IIS server. This should do the trick.

Good point above, you need the errorMail module BUT if you are not using a remote SMTP server you need SMTP locally, just to clarify.

참고URL : https://stackoverflow.com/questions/34401/send-email-from-elmah

반응형