send mail on button click
<p>i am trying to send mail on button click.  on local pc the code is working but on server the code is not working. it gives error "Unable to connect to the remote serverSource:-SystemData :- System.Collections.ListDictionaryInternal "  please help</p>

<p>home.aspx</p>

<pre><code>public partial class About : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SendContactUsEmail();
        SendAutoResponseEmail();

    }
    private bool SendContactUsEmail()
    {
        MailMessage MailObject = new MailMessage();

        MailObject.From = new MailAddress(ConfigurationSettings.AppSettings["EmailFrom"].ToString());
        MailObject.To.Add(new MailAddress("test@technosys.com"));
        MailObject.Subject = " technosys Contact Alert Subject : ";
        string ErrorHandling_Message = "Dear Manager," + " " + "&lt;br/&gt;" + "A customer want to contact you with following details:";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Name: vesh";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Email: test@technosys";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Company: technosys";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Phone: 123456789";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Message: Test mail on live server";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Sincerely" + "&lt;br&gt;" + "Web Controller" + "&lt;br&gt;" + "&lt;b&gt;Technosys&lt;/b&gt;";
        try
        {
            MailObject.Body = ErrorHandling_Message;
            MailObject.IsBodyHtml = true;
            MailObject.Priority = MailPriority.High;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new NetworkCredential(ConfigurationSettings.AppSettings["EmailFrom"].ToString(), ConfigurationSettings.AppSettings["Password"].ToString());
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(MailObject);
            Label1.Text = "Done";
            return true;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
            return false;
        }
    }
    private bool SendAutoResponseEmail()
    {
        MailMessage MailObject = new MailMessage();

        MailObject.From = new MailAddress(ConfigurationSettings.AppSettings["EmailFrom"].ToString());
        MailObject.To.Add(new MailAddress("test@technosys.com"));
        MailObject.Subject = "Thanks for your request at technosys";
        string ErrorHandling_Message = "Dear, " + "&lt;br/&gt;&lt;/br&gt;" + "Thanks for your email. You can expect to hear back from us with an answer to your inquiry within : 24 hours.";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;We look forward to helping you.";
        ErrorHandling_Message += "&lt;br&gt;&lt;br&gt;Sincerely" + "&lt;br&gt;" + "&lt;br&gt;" + "&lt;b&gt;Technosys&lt;/b&gt;" + "&lt;br&gt;&lt;img alt=\"\"  src=\"http:/images/logomain.jpg\" &gt;";
        try
        {
            MailObject.Body = ErrorHandling_Message;
            MailObject.IsBodyHtml = true;
            MailObject.Priority = MailPriority.High;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new NetworkCredential(ConfigurationSettings.AppSettings["EmailFrom"].ToString(), ConfigurationSettings.AppSettings["Password"].ToString());
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(MailObject);
            Label1.Text = "Done";
            return true;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
            return false;
        }
    }
}
</code></pre>

<p>web.config</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website-&gt;Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
--&gt;
&lt;configuration&gt;
    &lt;appSettings&gt;
        &lt;add key="EmailFrom" value="test@technosys.com"/&gt;
      &lt;add key="Password" value="best"/&gt;
    &lt;/appSettings&gt;
    &lt;connectionStrings/&gt;
    &lt;system.web&gt;
    &lt;customErrors  mode="Off"&gt;

    &lt;/customErrors&gt;
 &lt;!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        --&gt;
        &lt;compilation debug="true" targetFramework="4.0"&gt;
        &lt;/compilation&gt;
        &lt;!--
            The &lt;authentication&gt; section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        --&gt;
        &lt;authentication mode="Windows"/&gt;
        &lt;!--
            The &lt;customErrors&gt; section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        &lt;customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"&gt;
            &lt;error statusCode="403" redirect="NoAccess.htm" /&gt;
            &lt;error statusCode="404" redirect="FileNotFound.htm" /&gt;
        &lt;/customErrors&gt;
        --&gt;
        &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/&gt;&lt;/system.web&gt;
    &lt;!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    --&gt;
&lt;/configuration&gt;
</code></pre>
