2015-04-15 74 views
-2

下面的代碼在使用本地主機進行調試時工作正常,但在我發佈到Web服務器後無法正常工作。MailMessage smtpClient在發佈後不工作

protected void SendMail() 
    { 

     MailMessage mailMessage = new MailMessage(); 
     mailMessage.From = new MailAddress("[email protected]"); 
     mailMessage.To.Add("[email protected]"); 
     mailMessage.Subject = ddlSubject.Text; 

     mailMessage.Body = "<b>Sender Title: </b> " + ddlTitle.SelectedItem.Text + "<br/>" 
      + "<b>Sender First Name: </b> " + txtFName.Text + "<br/>" 
      + "<b>Sender Last Name: </b> " + txtLName.Text + "<br/>" 
      + "<b>Sender Email: </b> " + txtEmail.Text + "<br/>" 
      + "<b>Sender Phone: </b> " + txtPhone.Text + "<br/>" 
      + "<b>Sender Address: </b> " + txtAddress.Text + "<br/>" 
      + "<b>Sender Suburb: </b> " + ddlSuburbs.SelectedItem.Text + "<br/>" 
      + "<b>Sender Message: </b> " + contactMessage.InnerText + "<br/>"; 
     mailMessage.IsBodyHtml = true; 

     SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); 
     smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxxx"); 
     smtpClient.EnableSsl = true; 
     smtpClient.Send(mailMessage); 

     lblConfirmation.Text = "Thank you " + ddlTitle.SelectedItem.Text + " " + txtFName.Text.ToUpper() + " " + txtLName.Text.ToUpper() + " for contacting us. We will try to get back to you ASAP"; 
    } 

注意的網站使用SSL。

+0

您是否檢查過是否有任何防火牆規則或生產服務器上是否有代理? – BDH

+0

我正在使用goDaddy託管服務 – Deeyo

+0

也許您應該問他們是否阻止使用該端口的傳出流量。 – BDH

回答

0

確保端口= 25。

try 
    { 
      MailMessage msg = new MailMessage(); 
      MailAddress fromAdd = new MailAddress("[email protected]"); 
      msg.[To].Add("[email protected]"); 
      msg.Subject = "Choose Session Members"; 
      msg.From = fromAdd; 
      msg .IsBodyHtml = true; 
      msg.Priority = MailPriority.Normal; 
      msg .BodyEncoding = Encoding.Default; 
      msg.Body = "<center><table><tr><td><h1>Your Message</h1><br/><br/></td></tr>"; 
      msg.Body = msg.Body + "</table></center>"; 
      SmtpClient smtpClient = new SmtpClient ("smtp.yourserver.com", "25"); 
      smtpClient.EnableSsl = true; 
      smtpClient.UseDefaultCredentials = false; 
      smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); 
      smtpClient .DeliveryMethod = SmtpDeliveryMethod.Network; 
      smtpClient.Send(msg); 
      smtpClient.Dispose(); 
     } 
    catch (exception ex){ 
     Label1.Text = ex.ToString(); 
    } 
+0

無法正常工作,我也啓用了從我的電子郵件中安全性較低的應用程序訪問此錯誤消息的訪問權限:System.Net.Mail.SmtpException:SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.5.1需要身份驗證。 – Deeyo