title: Asp contact page works locally but not on a server
body: <p>I have an asp website and a contact form in asp that I found online. It runs perfectly on the local machine.</p>
  
  <p>I added it to my server to test it live, and it didn't work. I got the display message to display the error, and it says this:</p>
  
  <blockquote>
    <p>System.Security.SecurityException: Request for the permission of type
    'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0,
    Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at
    System.Security.CodeAccessSecurityEngine.Check(Object demand,
    StackCrawlMark&amp; stackMark, Boolean isPermSet) at
    System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
    cap, StackCrawlMark&amp; stackMark) at
    System.Security.CodeAccessPermission.Demand() at
    System.Net.Mail.SmtpClient.Initialize() at
    System.Net.Mail.SmtpClient..ctor(String host, Int32 port) at
    contact.btnSubmit_Click(Object sender, EventArgs e) in
    g:\pleskvhosts\myweburl\httpdocs\contact.aspx.cs:line 33 The action
    that failed was: Demand The type of the first permission that failed
    was: System.Net.Mail.SmtpPermission The Zone of the assembly that
    failed was: MyComputer</p>
  </blockquote>
  
  <p>Does anyone know what this means?</p>
  
  <p>My code for contact.aspx.cs is</p>
  
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
  {
      try
      {
          MailMessage mailMsg = new MailMessage();
  
          mailMsg.From = new MailAddress(TheirEmail.Text);
  
          mailMsg.To.Add("myemailaddress@gmail.com");
  
          mailMsg.IsBodyHtml = true;
  
          mailMsg.Subject = "Contact Question!";
  
          mailMsg.Body = "Contact Details" + "&lt;b&gt;Name:&lt;/b&gt;" + TheirName.Text + " &lt;br/&gt; &lt;b&gt;Email - address :&lt;/b&gt;" + TheirEmail.Text + "&lt;br/&gt; &lt;b&gt;Comments :&lt;/b&gt;" + Comments.Text;
  
          SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
  
          mailMsg.Priority = MailPriority.Normal;
  
          smtp.Credentials = new System.Net.NetworkCredential("myemailaddress@gmail.com", "mypassword");
  
          smtp.Timeout = 25000;
  
          smtp.EnableSsl = true;
  
          smtp.Send(mailMsg);
  
          TheirEmail.Text = "";
          TheirName.Text = "";
          Comments.Text = "";
  
  
          DisplayMessage.Text = "Thank you. Your contact details and feed back has been submitted.";
          DisplayMessage.Visible = true;
      }
  
      catch (Exception ex)
      {
          DisplayMessage.Text = ex.ToString();
          DisplayMessage.Visible = true;
      }
  </code></pre>