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.Subject="Contact From Our Website";

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


ob.Fields.Add("", "1");
ob.Fields.Add("", "");

ob.Fields.Add("", "password");




lblMsg.Text="Message Sent";


catch (Exception ex)


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


I hope this is useful.


Comments (5)

  1. Ravindra Sharma says:

    Good Work Sir

  2. N says:

    these classes (System.Web.Mail.*) are deprecated in ASP.NET 2.0 …

  3. Hassan Kamal says:

    Thanks for the nice explaination

    i would be pleased if you can answer my Q

    i hava a form which contains a data on it

    i want after clicking the update button or insert button the ASP.NET sends an automatic email to the user to welcome him in the database.


  4. owen says:

    is there any chance in getting this code please for the comment above

Skip to main content