How to send E-mail in using web.config? - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

How to send E-mail in using web.config?

Introduction:In this post I go to tell you to send E-mail using web.config. Sometime we create a web application and there is lot of form to send E-email to users. If in future E-mail address of Administration will change then we have to change the E-mail address of Administration in every web form.  If we want it would not happen in future so we mention the E-mail address detail in web.config file of application.
Now see how we can do it simply. Add the below mention information in web.config file.
    <add key="Email" value="your E-mail address"/>
      <smtp deliveryMethod="Network">
        <network enableSsl="true" port="587" host="" userName="E-mail addrerss" password="Password"/>
Now add a web form to application.
  <asp:ScriptManager ID="ScriptManager1" runat="server">
    <tr><td>Email Address</td><td>
        <asp:TextBox ID="txtemail" runat="server"></asp:TextBox></td></tr>
            <asp:TextBox ID="txtsubject" runat="server"></asp:TextBox></td></tr>
                <cc1:Editor ID="Editor1" runat="server" />
                <tr><td></td><td><asp:Button ID="dtnsend" runat="server" Text="Send" onclick="dtnsend_Click" />
Double click on Send button that redirect you to .aspx.cs page. Add the namespace to page.
using System.Net.Mail;
using System.Configuration;

On button click add below mention code:
protected void dtnsend_Click(object sender, EventArgs e)
            string Email = ConfigurationManager.AppSettings["Email"].ToString();
            string Emailto = txtemail.Text;
            MailMessage mail = new MailMessage(Email, Emailto);
            mail.Subject = txtsubject.Text;
            mail.Body = Editor1.Content ;
            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            Response.Write("Email send successfully");
        catch (Exception ex)

    public void Clear()
        txtemail.Text = "";
        Editor1.Content = "";
        txtsubject.Text = "";

Now debug the application and check the result.

Related Articles on Send Email:
How to Send Email with Attachment in

Is it helpful?

If yes post your comment to admire my work. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.


You can examine the services of all the companies and select the best one. Nevertheless, there are particular aspects that you need to think about while examining a cloud hosting company.