简体   繁体   中英

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="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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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