使用 ELMAH 在 ASP.Net MVC 5 中出错时发送电子邮件

Send Email when Error in ASP.Net MVC 5 using ELMAH

我正在尝试使用 Elmah 在我的代码出现异常时发送电子邮件。 这是 web.config 文件中的配置。

<elmah> 
    <errorMail from="MyEmailId@gmail.com" to="MyEmailId@gmail.com" 
                async="true"  smtpPort="0" useSsl="true" /> 
</elmah>
<system.net> 
    <mailSettings> 
        <smtp deliveryMethod ="Network"> 
            <network host="smtp.gmail.com" port="587" userName="MyEmailId@gmail.com"   password="MyEmailPassword" /> 
        </smtp> 
    </mailSettings> 
</system.net>

现在上面的配置工作正常。每次收到异常时,我都会在 localhost 中进行测试,我会成功收到一封电子邮件。

问题 1:

Does that mean if I deploy my application with above settings, no matter who ever access my website, if they get an exception I will receive an email.

问题 2:

I have added password in above config file. But now everyone can see my password. Is this the right way or I can still send the mail w/o putting my password in config file.

问题 1 的答案:

Exceptions will be caught irrespective of the type of error module you use. So you will definitely receive an email in those exception cases.

问题 2 的答案:

Why are you using your personal mail id? Create a new ID and use it for the purpose, so that even if others see, it doesn't have any effect. Others means only the developers will be able to see, not the public. You can encrypt the web.config file by checking this MSDN article. Also consider encrypting your password and storing it in the web,config file.