连接到主机端口25时出现问题
本文关键字:问题 25时 主机 连接 | 更新日期: 2023-09-27 18:25:44
我在Arvixe工作了很多年,最近他们更改了所有权并执行了各种迁移。他们的许多客户都遇到了问题。
这是ASP.NET 4.5 Web应用程序
自从他们迁移以来,当我的网站用户试图通过以下表格发送电子邮件时,我会遇到异常:http://goo.gl/zz7FeH
消息"无法连接到远程服务器"
InnerException{"连接尝试失败是因为连接方在一段时间后没有正确响应,或者建立的连接失败是因为所连接的主机未能响应104.27.1.886.185:25"}System.Exception{System.Net.SocketException}
我已经用Telnet检查了这个端口,似乎可以连接:telnet smtp.davincispainting.com 25
这是邮件服务代码:
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;
}
能够连接:telnet smtp.davincispainting.com 25
但在你的代码中:
SmtpClient emailClient = new SmtpClient("mail.davincispainting.com", 25);
您在这里使用不同的主机,这些主机解析到不同的IP地址:smtp.xxx解析到143.95.251.2,而mail.xxx解析为104.27186.185。在第一个端口上连接到端口25有效,而在第二个端口上则无效。