Unbreakable
Unbreakable

Reputation: 8084

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. Here is the configuration in web.config file.

<elmah> 
    <errorMail from="[email protected]" to="[email protected]" 
                async="true"  smtpPort="0" useSsl="true" /> 
</elmah>
<system.net> 
    <mailSettings> 
        <smtp deliveryMethod ="Network"> 
            <network host="smtp.gmail.com" port="587" userName="[email protected]"   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.

Question 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:

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.

Upvotes: 3

Views: 1023

Answers (1)

ViVi
ViVi

Reputation: 4464

Answer to question 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 :

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.

Upvotes: 1

Related Questions