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 asp.net.
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,
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
protected void btnSend_Click(object sender, EventArgs e)
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
client.Port = 587;
client.Host = “smtp.gmail.com”;
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 asp.net,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.