how to send email in ASP.NET

No.of Views1871
Bookmarked0 times
By  NikhilJohari   On  16 Feb 2010 03:02:18
Tag : ASP.NET , Miscellaneous
how to send email in ASP.NET
emailbookmarkadd comments print

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at



 In this article we will create a tool by which we can send the email to one person, we will not use BCc and Cc.So get ready to create a simple e-mail sending tool in

First type this code in source code window to create the user interface of email-sending tool by using html code .


When you are look designed GUI lokk like followings,

Image Loading

Now in design window double click the button (Send) to give the code,Before writing this code you have to specify a namespace which is

using System.Net.Mail;


protected void btnSend_Click(object sender, EventArgs e)
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
client.Port = 587;
client.Host = “”;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(txtemail.Text ,txtpass.Text );
client.EnableSsl = true;
MailAddress SendTo = new MailAddress(txtTo.Text);
MailAddress SendFrom = new MailAddress(txtFrom.Text);
message = new MailMessage(SendFrom, SendTo);
message.Body = txtMessage.Text;
message.Subject = txtSub.Text;
txtStatus.Text = “Your email has been sent”;
Page.RegisterClientScriptBlock(”Thanks!”, “alert(’Thanks! for using this tool.’)”);
catch (Exception ex)
txtStatus.Text = ex.ToString();


Now we have created a tool for sending e-mail through,but by using this tool we can only send one email at a time we can’t send mails to BCc or Cc ,in my next upcoming articles i will show you how to send BCc and Cc email by doing a bit changes in this code and after that blog i will show you how to send attachments by just adding some more lines of code.
It is really very fun work and very important also.

Now run this code and fill all the Text Boxes right and then check your email id you will get there a send or inbox mail,And try to do write this code by your own in spite copy and paste this code.


In this article, you have learn , how to send email using .NET namespace in ASP.NET. i hope this help ASP.NET beginners.

Sign Up to vote for this article
About Author
Member Type-Senior
Joined date-15 Aug 2009
Home Page-
Blog Page-
Other popularSectionarticles
There is no comments for this articles.
Leave a Reply
Display Name:
(not display in page for the security purphase)
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top