views:

21

answers:

2

Hello Friends,

I need to send and Email when Any Message occurs I am trying to logg the errors once I logged it I need to send the Email to them..

Thanks

A: 

A compbination of ELMAH and System.Net.Mail...

ELMAH:

http://code.google.com/p/elmah/

System.Net.Mail Namespace:

http://msdn.microsoft.com/en-us/library/system.net.mail.aspx

In Code:

using System.Net.Mail;
// ...
SmtpClient mailClient = new SmtpClient();
mailClient.Send(from, to, subject, body);

In Web.Config:

<system.net>
   <mailSettings>
      <smtp [email protected]>
         <network host="smtp.gmail.com"
                  password="your_pwd"
                  port="587"
            userName="[email protected]"/>
      </smtp>
   </mailSettings>
</system.net>
Alexander
what do I need use to send an Email to Gmail SmtpClient client = new SmtpClient(); client.Send(message);? I mean to say Host? and port?
just edited my answer, per your comment...
Alexander
A: 

You can use log4net as your infrastructure of logging and in the config add an email appender (EventLogAppender).

pablito