简体   繁体   English

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

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

I am trying to send email whenever there is an exception in my code using Elmah . 我试图在使用Elmah的代码中发生异常时发送电子邮件。 Here is the configuration in web.config file. 这是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>

Now above configuration works fine. 现在上面的配置工作正常。 I tested in localhost every time I get an exception I am getting an Email Successfully. 我每次收到异常时都会在localhost中测试我收到了一封电子邮件。

Question 1: 问题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. 这是否意味着如果我使用上述设置部署我的应用程序,无论谁访问我的网站,如果他们得到例外,我将收到一封电子邮件。

Question 2: 问题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. 这是正确的方式还是我仍然可以发送邮件,而不是将我的密码放在配置文件中。

Answer to question 1 : 回答问题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. 因此,您肯定会在这些例外情况下收到一封电子邮件。

Answer to question 2 : 对问题2的回答:

Why are you using your personal mail id? 你为什么使用你的个人邮件ID? Create a new ID and use it for the purpose, so that even if others see, it doesn't have any effect. 创建一个新ID并将其用于此目的,以便即使其他人看到它也没有任何效果。 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 . 您可以通过查看此MSDN文章来加密web.config文件。 Also consider encrypting your password and storing it in the web,config file. 还要考虑加密密码并将其存储在Web配置文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM