Getting Error while using email used in my project .........

My email function does not work , when I have uploaded my project on my server ......Please help...Do I need to change the Port no after uploading....


My function is as follows
             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
                SqlCommand com = new SqlCommand("Select Email from Primary_Member where Flat = '" + id + "'", conn);
                SqlDataReader dr = com.ExecuteReader();
                if (dr.Read())
                    HiddenFieldE.Value = dr["Email"].ToString();

            var messagefrom = "";
            var toAddress = HiddenFieldE.Value;
            string messageBody = "You have been successfully registered by the admin and your username is '"+HiddenFieldE.Value+"' and password is '"+pass+"'";
            string fromPassword = "nid100"; 
            var subject = "Confirmation Email";
            var client = new SmtpClient
                Host = "",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(messagefrom, fromPassword)

            using (var msg = new MailMessage(messagefrom, toAddress)
                Subject = subject,
                Body = messageBody


            SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            String update = "Update Primary_Member set Approved = @reg where Flat = '" + id + "'" ;
            SqlCommand com1 = new SqlCommand(update, conn1);
            String insertQuery = "insert into UserData (USerName , Password , Roll_Id) values(@uname ,  @upass , @id)";
            SqlCommand com2 = new SqlCommand(insertQuery, conn1);      
            com2.Parameters.AddWithValue("@uname",  HiddenFieldE.Value);
            com2.Parameters.AddWithValue("@upass", pass);
            com2.Parameters.AddWithValue("@id", "2");
            com1.Parameters.AddWithValue("@reg", "Approved");


            ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myFunction();", true);

        catch (Exception ex)

Open in new window

Sukesh ShuklaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Since it's your own server, you have full rights to it, and you can change this to your Web.config file:

    <trust level="Full" originUrl=""/>

Open in new window

The moment you change the default port number 25, security kicks in. This line tells the server it should trust this code. On a shared server, you probably would have a problem.
Sukesh ShuklaAuthor Commented:
I did the following changes , but a new error occured nowUntitled3.png
My config file is as follows
<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit
    <!-- For more information on Entity Framework configuration, visit -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <add name="DefaultConnection" connectionString="Server=;Database=mbmci5ko_society;Uid=society;Password=b1Jga74@0;" providerName="System.Data.SqlClient" />
    <add name="HousingConnectionString" connectionString="Server=;Database=mbmci5ko_society;Uid=society;Password=b1Jga74@0;" providerName="System.Data.SqlClient" />

    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.5">
        <add assembly="System.Design, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <trust level="Full" originUrl=""/>
    <httpRuntime targetFramework="4.5"/>
        <add namespace="System.Web.Optimization"/>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx"/>
      <deny users="?"/>
    <profile defaultProvider="DefaultProfileProvider">
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
    <membership defaultProvider="DefaultMembershipProvider">
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    <roleManager defaultProvider="DefaultRoleProvider">
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="v11.0"/>

Open in new window

Are you sure it's YOUR OWN SERVER? I mentioned a server being your own (full rights) or being a shared server (rights set by provider).
If it's a shared server, the extra line will not help you. Please answer this question first.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Sukesh ShuklaAuthor Commented:
No its not my own server.......Its a shared one
As I said, a shared server will have these problems because of security restrictions. Only THE server admin will be able to help you, in this case, the owner or provider of the server.
Explain what you are trying to achieve (maybe provide a bit of the code), and they'll either have a workaround, or are willing to lift the restriction for you (probably not).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sukesh ShuklaAuthor Commented:
Ok thank you Kimputer...........
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.