Sending an Email using ASP.NET 2.0

Sending an Email is quite easy in ASP.NET 2.0. You can use the .NET Class SMTPMail to send the messages. The tricky part is when your server needs authentication. Many of the programmers stuck when it comes to pass UserName and Password of the SMTP Mail account to the server in order to send the email.
I am giving here the way to pass the username and password to send an email. Generally, it is required when you actually host your website on a shared third party web server.

System.Web.Mail.MailMessage ob= new MailMessage();
ob.To="info@YourDomaincom";
ob.From="mail@YourDomain.com";

ob.Subject="Contact From Our Website";

ob.Body= "Name :" + txtName.Text + "
" +"Email:" + txtEmail.Text ; ob.Priority=MailPriority.High;

SmtpMail.SmtpServer="mail.YourDomain.com";

ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/sendusername", "Email@YourDomain.com");

ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/sendpassword", "password");

try

{

SmtpMail.Send(ob);

lblMsg.Text="Message Sent";

}

catch (Exception ex)

{

Response.Write("Send failure: " + ex.Message);

}

I hope this is useful.

~Sandeep