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

时间:2014-11-19 08:43:33

标签: asp.net email web-hosting

我已将我的网站上传到一个已知的托管服务器,我有一个联系表格,奇怪的是,当我从visual studio(asp.net语言)运行网站时,我的收件箱发送的电子邮件很好。我将它上传到托管服务器上的时间它给出了错误:failure sending the email.我正在使用smtp.gmail.com,端口:587,用户名和pass和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>

我在没有任何帮助的情况下联系了托管服务提供商。 提前谢谢。

0 个答案:

没有答案
相关问题