Asp.net 上传的网站不发送电子邮件

Asp.net 上传的网站不发送电子邮件,asp.net,email,web-hosting,Asp.net,Email,Web Hosting,我已经将我的网站上传到一个已知的托管服务器,并且我有一个联系表单,奇怪的是,当我从visual studio运行网站时,asp.net语言在我的收件箱中发送电子邮件很正常。从我将其上传到托管服务器时,它给出了错误:发送电子邮件失败。我正在使用smtp.gmail.com,端口:587,用户名、密码和ssl已启用 protected void sendClientMail(string emailto) { try {

我已经将我的网站上传到一个已知的托管服务器,并且我有一个联系表单,奇怪的是,当我从visual studio运行网站时,asp.net语言在我的收件箱中发送电子邮件很正常。从我将其上传到托管服务器时,它给出了错误:发送电子邮件失败。我正在使用smtp.gmail.com,端口:587,用户名、密码和ssl已启用

   protected void sendClientMail(string emailto)
        {

            try
            {
                var mail = new MailMessage
                {
                    BodyEncoding = Encoding.UTF8,
                    From = new MailAddress(ConfigurationManager.AppSettings["MAILFROM"])
                };

                mail.To.Add(emailto);
                mail.Bcc.Add(ConfigurationManager.AppSettings["MAILBCC"]); //sends to my email also
                mail.Subject=ConfigurationManager.AppSettings["CLIENT-MAILSUBJECT"];

                mail.IsBodyHtml = true;

                #region //Load Email Control and get HTML string

                string mailBody = "";
                {
                    PrintPlaceHolder.Visible = true;

                    var sb = new StringBuilder();
                    var writer = new HtmlTextWriter(new StringWriter(sb));

                    var emailctl = LoadControl("~/Controls/ClientEmail.ascx") as ClientEmail;

                    if (emailctl != null)
                    {
                        emailctl.Name = txtName.Text;
                        emailctl.IntroName = txtName.Text + " " + txtSurname.Text;
                        emailctl.Surname = txtSurname.Text;
                        emailctl.Mobile = txtMobile.Text;
                        emailctl.Phone = txtPhone.Text;
                        emailctl.City = txtCity.Text;
                        emailctl.Street = txtStreet.Text;
                        emailctl.Message = txtmessage.Text;
                        emailctl.Email = txtEmail.Text;
                        emailctl.Country = ddlCountry.SelectedValue;

                        PrintPlaceHolder.Controls.Add(emailctl);
                        emailctl.RenderControl(writer);
                    }

                    mailBody = sb.ToString();
                    if (emailctl != null)
                    {
                        emailctl.Dispose();
                    }
                    writer.Dispose();
                    sb.Clear();
                    PrintPlaceHolder.Visible = false;
                }

                #endregion

                mail.Body = mailBody;

                //mail.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();

                client.Credentials = new NetworkCredential (ConfigurationManager.AppSettings["MAILFROM"], ConfigurationManager.AppSettings["PASS"]);
                client.Host = ConfigurationManager.AppSettings["SMTPSERVER"];
                client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPORT"]);
                //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl= false;
                //client.UseDefaultCredentials = true;

                client.Send(mail);

                clearFields();

                Response.Write("<script>alert('"+ConfigurationManager.AppSettings["MAILSUCCESS"]+"');</script>");

            }
            catch (Exception e)
            {
                Response.Write("<script>alert('"+ ConfigurationManager.AppSettings["MAILFAIL"] +" Error: "+e+"')</script>");
            }

        }//end method
Web.config文件代码:

<?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>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
    <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
      <add key="CLIENT-MAILSUBJECT" value="Mario Website - Confirmation Email"/>
      <add key="MY-MAILSUBJECT" value="Mario Website - Email Sent"/>
      <add key="MAILFROM" value="mariotec@mario26tech.com"/>
      <add key="MAILBCC" value="nikolaou_marios@hotmail.com"/>
      <add key="SMTPSERVER" value="sns41.win.hostgator.com"/>
      <add key="SMTPPORT" value="26"/>
      <add key="PASS" value="pass"/>
      <add key="MAILSUCCESS" value="Email was sent successfully, thank you for your interest!!!"/>
      <add key="MAILFAIL" value="There was an error while sending the email."/>
    </appSettings>

   <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <clear/>
        <add value="Index.aspx"/>
      </files>
    </defaultDocument>
  </system.webServer>

</configuration>
我已经联系了主机提供商,没有任何帮助。
提前感谢。

您是否尝试过使用web.config中的端口25而不是26并启用SSL?你有没有检查过你的Gmail设置,以供参考。为什么我在本地电脑上运行时它工作正常?当我把它上传到服务器上时,它不起作用。你得到了什么异常?记录并检查内部异常。