2015-12-05 30 views
0

我已經在Arvixe工作了很多年,最近他們改變了所有權並執行了各種遷移。他們的許多客戶都有問題。問題連接到主機端口25

這是ASP.NET 4.5 Web應用程序

自從遷徙我得到一個異常時,我的網站嘗試用戶通過表單發送電子郵件: http://goo.gl/zz7FeH

消息「無法連接到遠程服務器「

InnerException {」連接嘗試失敗,因爲連接方在一段時間後沒有正確響應,或者建立的連接失敗,因爲連接的主機未能響應104.27.186.185:25「}系統。異常{System.Net.S ockets.SocketException}

我檢查這個端口Telnet和似乎能夠連接: 的telnet smtp.davincispainting.com 25

這裏是MailService的代碼:

public class EstimateContactInfo 
{ 
public string Email { get; set; } 
public string Name { get; set; } 
public string Company { get; set; } 
public string Address1 { get; set; } 
public string Address2 { get; set; } 
public string Phone { get; set; } 
public string City { get; set; } 
public string State { get; set; } 
//public string Zip { get; set; } 
public string Customer { get; set; } 
public string ServiceType { get; set; } 
public string JobDescription { get; set; } 

public override string ToString() 
{ 
    return string.Format(@"Name: {0}<br/><br/>Company: {1}<br/><br/>Email Address: {2}<br/><br/>Phone: {3}<br/><br/> 
      Address1: {4}<br/><br/>Address2: {5}<br/><br/>City: {6}<br/><br/>Sate: {7}<br/><br/>Customer: {8}<br/><br/>ServiceType: {9}<br/><br/>JobDescription: {10}", 
      Name, Company, Email, Phone, Address1, Address2, City, State, Customer, ServiceType, JobDescription); 
} 
} 

public class MailService 
{ 

public MailService() 
{ 

} 

private bool IsValidateEmail(string email) 
{ 
    return Regex.IsMatch(email, @".*@.{2,}\..{2,}"); 
} 

public string GetToken(int contactNum) 
{ 
    string extendKey = string.Format("smcf-{0}{1}{2}", System.Configuration.ConfigurationManager.AppSettings["ContactEmail" + contactNum.ToString()], DateTime.Now.Month, DateTime.Now.Day); 
    Byte[] originalBytes; 
    Byte[] encodedBytes; 
    MD5 md5; 

    //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password) 
    md5 = new MD5CryptoServiceProvider(); 
    originalBytes = ASCIIEncoding.Default.GetBytes(extendKey); 
    encodedBytes = md5.ComputeHash(originalBytes); 

    //Convert encoded bytes back to a 'readable' string 
    return BitConverter.ToString(encodedBytes); 
} 

public void SendMail(string from, string to, string subject, string content, string cc) 
{ 
    if (!IsValidateEmail(from)) 
    { 
     from = to; 
     subject += " - invalid email"; 
     content += "\n\nBad email:" + content; 
     cc = null; 
    } 
    MailMessage message = new MailMessage(from, to, subject, content); 

    message.IsBodyHtml = true; 
    if (cc != null) 
     message.CC.Add(cc); 

    SmtpClient emailClient = new SmtpClient("mail.davincispainting.com", 25); 

    string pwd = "ninja71"; 

    NetworkCredential credentials = new NetworkCredential(from, pwd); 
    emailClient.Credentials = credentials; 

    emailClient.Send(message); 
} 

public void SubmitContact(EstimateContactInfo contactInfo, int cc) 
{ 
    //SendMail(System.Configuration.ConfigurationManager.AppSettings["ContactEmail1"], System.Configuration.ConfigurationManager.AppSettings["ContactEmail1"], "Request Estimate", contactInfo.ToString(), cc > 0 ? contactInfo.Email : null); 
    SendMail(ConfigurationManager.AppSettings["ContactEmail1"], System.Configuration.ConfigurationManager.AppSettings["ContactEmail1"], "Request Estimate", contactInfo.ToString(), cc > 0 ? contactInfo.Email : null); 
} 
} 

這裏調用MailService.cs:

public partial class painting_estimate : System.Web.UI.Page 
{ 
    protected void btnSendGenMail_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      MailService mailService = new MailService(); 
      EstimateContactInfo contactInfo = new EstimateContactInfo(); 
      contactInfo.Name = txtGenName.Text; 
      contactInfo.Company = txtGenCompany.Text; 
      contactInfo.Email = txtGenEmail.Text; 
      contactInfo.Phone = txtGenPhone.Text; 
      contactInfo.Address1 = txtGenAddy1.Text; 
      contactInfo.Address2 = txtGenAddy2.Text; 
      contactInfo.City = txtGenCity.Text; 
      contactInfo.State = ddGenState.Text; 
      contactInfo.Customer = ddGenCustomer.SelectedItem.Text; 
      contactInfo.ServiceType = ddGenJobType.SelectedItem.Text; 
      contactInfo.JobDescription = txtGenMessage.Text; 

      mailService.SubmitContact(contactInfo, 0); 
      SubmitSuccess.Visible = true; 
     } 
     catch (Exception se) 
     { 
      SubmitError.Visible = true; 
     } 

     ContactPanel.Visible = false; 
    } 
+0

請參閱下面的網頁以獲取不同端口號的列表。您正在使用郵件服務器之間使用的端口25進行測試。您的應用程序正在使用端口587,這是用於客戶端郵件服務器提交給郵件服務器的安全端口。與您的郵件服務器一起檢查以獲取與Microsoft SMTP客戶端一起使用的確切參數。網絡證書可能是錯誤的。 https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers – jdweng

+0

@jdweng Port 587實際上是我嘗試的一項測試。實際生產站點使用端口25.我已經使用端口587和端口25進行了測試。 – Paul

+0

您可以使用測試代碼發送郵件嗎?港口是否被封鎖? – gmalenko

回答

0

...能夠連接:遠程登錄smtp.davincispaintin g.com 25

但在你的代碼:

SmtpClient emailClient = new SmtpClient("mail.davincispainting.com", 25); 

您可以使用此不同的主機,其決心不同的IP地址:smtp.xxx解析爲143.95.251.2而mail.xxx決議104.27.186.185。在第一個作品上連接到端口25,而在第二個作品上不連接。

+0

我的印象是smtp.xxx和mail.xxx指向同一個SMTP?我將如何解決這個問題? – Paul

+0

Paul:我一直在說要聯繫郵件服務器網站。每個郵件服務器有不同的參數。有時郵件服務器參數會發生變化,因此您必須聯繫郵件服務器。 – jdweng

+0

另外您正在使用可能不正確的網絡憑據。本地PC密碼服務器是否與郵件服務器相同?您可能需要使用用戶登錄到PC的默認憑據與郵件服務器相同的帳戶/密碼。如果SMPT被防火牆阻止,您也可能需要使用代理服務器才能通過防火牆。檢查您的病毒防護和防火牆以確保端口未被阻止。 – jdweng

相關問題