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....


Untitle1.png

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

                     dr.Close();
                    conn.Close();
                }
            
            var messagefrom = "nidhi@indweb.com";
            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 = "smtp.gmail.com",
                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
            }
            )

            {
                client.Send(msg);
            }

            SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            conn1.Open();
            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");

            com1.ExecuteNonQuery();
            com2.ExecuteNonQuery();
            conn1.Close();




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

        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

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.

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

<configuration>
  <system.web>
    .....
    <trust level="Full" originUrl=""/>
  </system.web>
</configuration>

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.
0
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
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Server=208.91.198.196;Database=mbmci5ko_society;Uid=society;Password=b1Jga74@0;" providerName="System.Data.SqlClient" />
    <add name="HousingConnectionString" connectionString="Server=208.91.198.196;Database=mbmci5ko_society;Uid=society;Password=b1Jga74@0;" providerName="System.Data.SqlClient" />
  </connectionStrings>




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

  </system.web>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

Open in new window

0
KimputerCommented:
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.
0
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
0
KimputerCommented:
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).
0

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...........
0
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
ASP.NET

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.