Click here to Skip to main content
11,935,012 members (50,387 online)
Click here to Skip to main content
Add your own
alternative version


87 bookmarked

Send Email in ASP.Net 2.0 - Feed back Form

, 1 Jan 2006
Rate this:
Please Sign up or sign in to vote.
This article explains how to send email using System.Net.Mail.SmtpClient in ASP.Net 2.0. with an example of Feedback form.

Sample Image - EmailApplication.jpeg


We are using System.Web.Mail.SmtpMail to send email in dotnet 1.1 which is obsolete in 2.0. The System.Net.Mail.SmtpClient Class will provide us the same feature as that of its predecessor.

This article explains how to use System.Net.Mail namespace to send emails.

Using the code

The HTML Design contains provision to enter sender’s name, email id and his comments. On click of the send email button the details will be sent to the specified email (Admin).

The Send mail functionality is similar to Dotnet 1.1 except for few changes

  1. System.Net.Mail.SmtpClient is used instead of System.Web.Mail.SmtpMail (obsolete in Dotnet 2.0).
  2. System.Net.MailMessage Class is used instead of System.Web.Mail.MailMessage (obsolete in Dotnet 2.0)
  3. The System.Net.MailMessage class collects From address as MailAddress object.
  4. The System.Net.MailMessage class collects To, CC, Bcc addresses as MailAddressCollection.
  5. MailMessage Body Format is replaced by IsBodyHtml

The Code is Self explanatory by itself.

      protected void btnSendmail_Click(object sender, EventArgs e)
        // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
        // System.Net.Mail.SmtpClient is the alternate class for this in 2.0
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

            MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost 
            smtpClient.Host = "localhost";

            //Default port will be 25
            smtpClient.Port = 25;

            //From address will be given as a MailAddress Object
            message.From = fromAddress;

            // To address collection of MailAddress
            message.Subject = "Feedback";

            // CC and BCC optional
            // MailAddressCollection class is used to send the email to various users
            // You can specify Address as new MailAddress("")

            // You can specify Address directly as string
            message.Bcc.Add(new MailAddress(""));
            message.Bcc.Add(new MailAddress(""));

            //Body can be Html or text format
            //Specify true if it  is html message
            message.IsBodyHtml = false;

            // Message body content
            message.Body = txtMessage.Text;
            // Send SMTP mail

            lblStatus.Text = "Email successfully sent.";
        catch (Exception ex)
            lblStatus.Text = "Send Email Failed." + ex.Message;


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gowrisankar K
Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow to send reply mail to client Pin
Sumit_Rj19-Sep-15 3:34
memberSumit_Rj19-Sep-15 3:34 
QuestionMail Sending Code error Pin
Member 1047274317-Dec-13 9:23
memberMember 1047274317-Dec-13 9:23 
QuestionERROR Pin
Ahsan Aftab23-Sep-13 0:58
memberAhsan Aftab23-Sep-13 0:58 
AnswerRe: ERROR Pin
Member 1086357610-Mar-15 0:02
memberMember 1086357610-Mar-15 0:02 
GeneralMy vote of 5 Pin
Vedangi25-Feb-13 21:53
memberVedangi25-Feb-13 21:53 
QuestionOn sending messages Pin
Bhuchetana1-Feb-13 6:05
memberBhuchetana1-Feb-13 6:05 
GeneralMy vote of 5 Pin
aacchee18-Jan-13 17:39
memberaacchee18-Jan-13 17:39 
GeneralMy vote of 5 Pin
Betty.888-Jan-13 23:01
memberBetty.888-Jan-13 23:01 
GeneralThanks Pin
rasikatharanga6-Dec-12 21:33
memberrasikatharanga6-Dec-12 21:33 
QuestionError While Sending Email Pin
Rahul.khurana31-Oct-12 2:21
memberRahul.khurana31-Oct-12 2:21 
Questionhow to post html data to .aspx file and save data Pin
gunanithi28-Aug-12 20:07
membergunanithi28-Aug-12 20:07 
GeneralMy vote of 5 Pin
visha vilas kulkarni3-Jul-12 22:05
membervisha vilas kulkarni3-Jul-12 22:05 
Questionsend email from Pin
Member 889955628-Apr-12 8:45
memberMember 889955628-Apr-12 8:45 
QuestionFeedback form Pin
Abhay .S. Patil22-Mar-12 21:50
memberAbhay .S. Patil22-Mar-12 21:50 
QuestionFeedback Pin
siddhesh.shinde1916-Feb-12 4:53
membersiddhesh.shinde1916-Feb-12 4:53 
AnswerRe: Feedback Pin
shobhit_7-Mar-12 20:40
groupshobhit_7-Mar-12 20:40 
AnswerRe: Feedback Pin
Andrew G Avelin4-Jun-12 21:28
memberAndrew G Avelin4-Jun-12 21:28 
QuestionSending Mail in ASP.Net Pin
Kamal Sukla14-Nov-11 23:00
memberKamal Sukla14-Nov-11 23:00 
Generalnot working Pin
mahendra0728-Nov-11 22:09
membermahendra0728-Nov-11 22:09 
GeneralMy vote of 1 Pin
yograjchaple3-Sep-11 1:37
memberyograjchaple3-Sep-11 1:37 
Questionsending mail error Pin
princeJasper2-Jul-11 0:58
memberprinceJasper2-Jul-11 0:58 
QuestionError ! Pin
razieh_mohammadi25-Jun-11 5:30
memberrazieh_mohammadi25-Jun-11 5:30 
Generalnice Pin
sneha_sharma12-May-11 1:00
membersneha_sharma12-May-11 1:00 
GeneralMy vote of 3 Pin
ali5318-May-11 22:10
memberali5318-May-11 22:10 
GeneralC# Code for sending email in ASP.NET Pin
michaelmeyer8-Mar-11 23:43
membermichaelmeyer8-Mar-11 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 2 Jan 2006
Article Copyright 2005 by Gowrisankar K
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid