Send email on error in ASP.Net MVC 5 using ELMAH

I am trying to send an email whenever there is an exception in my code using Elmah . Here is the configuration in the web.config file.

<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 the config is working fine. I have tested in localhost every time I get an exception I get the message successfully.

Question 1:

Does this mean that if I deploy my application with the above settings, question that has ever reached my site, if they get an exception, I will get an email.

Question 2:

I added the password to the config file above. But now everyone can see my password. Is this correct, or can I send mail without putting my password in the config file.

+3


source to share


1 answer


Answer to question 1:

Exceptions will be caught regardless of the type of error module you are using. Thus, you will definitely receive an email in these exception cases.



Answer to question 2:

Why are you using your personal email ID? Create a new ID and use it for this purpose, so that even if others see it has no effect. Others mean that only developers will be able to see, not the public. You can encrypt your web.config file by installing this MSDN article . Also consider encrypting your password and saving it to a web config file.

+1


source







All Articles