title: sending mail in asp.net-also using web config
body: <p>i am tryiung to create a contact us page ,where the user clicks submit and sends an email to me, i looked at some examples, but they seem to be hard coding their email credentials into the code, i found out that for security m you can store the username and password in the webconfig file, below is my web config code and my default aspx.cs code, could anybody please help me solve the problem, this is the error i get </p>
  
  <blockquote>
    <p>The remote name could not be resolved: 'smtp.gmail.com,587'     Line 45:             mailClient.Send(message);    </p>
  </blockquote>
  
  <p>Here is my appsettings and code:</p>
  
  <pre><code>        &lt;appSettings&gt;
          &lt;add key="PFUserName" value="myemail@gmail.com"/&gt;
      &lt;add key="PFPassWord" value="mypassword"/&gt;
     &lt;add key="MailServerName" value="smtp.gmail.com,587"/&gt;
      &lt;/appSettings&gt;
  
  
        using System;
     using System.Data;
     using System.Configuration;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
        using System.Web.UI.WebControls.WebParts;
        using System.Web.UI.HtmlControls;
      using System.Net.Mail;
      using System.Web.Configuration;
    using System.Net;
  
   namespace WebApplication2 
          {
  public partial class Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
      {
          SendMail(txtEmail.Text, txtComments.Text);
      }
  
      private void SendMail(string from, string body)
      {
          string Username = WebConfigurationManager.AppSettings["PFUserName"].ToString();
          string Password = WebConfigurationManager.AppSettings["PFPassWord"].ToString();
          string MailServer = WebConfigurationManager.AppSettings["MailServerName"].ToString();
          NetworkCredential cred = new NetworkCredential(Username, Password);
          string mailServerName = ("smtp.gmail.com,587");
  
  
  
          MailMessage message = new MailMessage(from, Username, "feedback", body);
          SmtpClient mailClient = new SmtpClient("smtp.gmail.com,587");
          mailClient.EnableSsl = true;
  
          mailClient.Host = mailServerName;
          mailClient.UseDefaultCredentials = false;
          mailClient.Credentials = cred;
          mailClient.Send(message);
          message.Dispose();
  
      }
  }
  </code></pre>
  
  <p>}</p>