C# 连接到主机端口25的问题

C# 连接到主机端口25的问题,c#,asp.net,sockets,C#,Asp.net,Sockets,我在Arvixe工作了很多年,最近他们改变了所有权并执行了各种迁移。他们的许多客户都有问题 这是ASP.NET 4.5 Web应用程序 自从他们迁移以来,我的网站的用户试图通过表单发送电子邮件时,我遇到了一个例外: 消息“无法连接到远程服务器” InnerException{“由于连接方在一段时间后没有正确响应,连接尝试失败,或者由于连接的主机未能响应104.27.186.185:25”}System.Exception{System.Net.Sockets.SocketException}

我在Arvixe工作了很多年,最近他们改变了所有权并执行了各种迁移。他们的许多客户都有问题

这是ASP.NET 4.5 Web应用程序

自从他们迁移以来,我的网站的用户试图通过表单发送电子邮件时,我遇到了一个例外:

消息“无法连接到远程服务器”

InnerException{“由于连接方在一段时间后没有正确响应,连接尝试失败,或者由于连接的主机未能响应104.27.186.185:25”}System.Exception{System.Net.Sockets.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);
}
}
。。。能够连接:telnet smtp.davincispainting.com 25

但在您的代码中:


这里您使用不同的主机解析为不同的IP地址:smtp.xxx解析为143.95.251.2,而mail.xxx解析为104.27.186.185。在第一个端口上连接到端口25,而在第二个端口上连接不起作用。

有关不同端口号的列表,请参阅下面的网页。您正在使用端口25进行测试,该端口用于到邮件服务器之间的连接。您的应用程序正在使用端口587,这是一个用于客户端邮件服务器提交到邮件服务器的安全端口。请与邮件服务器联系,以获取用于Microsoft SMTP客户端的确切参数。网络凭据可能是错误的@jdweng端口587实际上是我正在尝试的一个测试。实际生产现场使用端口25。我已经用端口587和端口25进行了测试。你能用测试代码发送邮件吗?端口被阻止了吗?@jdweng我曾尝试通过网站使用端口25和587发送邮件,但失败了。我不确定如何使用其他方法进行测试。有4个或5个不同的SMPT端口号。见我发布的网页。查看邮件服务器帮助页面(或呼叫支持)以获得正确的设置jdweng 3分钟前Edti觉得smtp.xxx和mail.xxx指向同一个smtp?我怎么解决这个问题呢?保罗:我一直说联系邮件服务器网站。每个邮件服务器都有不同的参数。有时邮件服务器参数会更改,因此您必须联系邮件服务器。此外,您使用的网络凭据可能不正确。本地PC密码服务器是否与邮件服务器相同?如果用户登录到电脑的帐户/密码与邮件服务器相同,则可能需要使用默认凭据。如果SMPT被防火墙阻止,您可能还需要使用代理服务器通过防火墙。检查您的病毒防护和防火墙,确保端口未被阻止。@jdweng可能服务器参数已更改,因为新主机公司更改了某些内容,尽管它是相同的服务器名称。凭据尚未更改。我不确定这是否是防火墙问题,因为此问题发生在服务器上的网站上。您使用的是intranet Outlook邮件服务器还是Internet POP邮件服务器?我假设您可以使用相同的凭据手动获取电子邮件。我见过POP服务器将SMTP端口号从非安全端口号更改为安全端口号的情况。如果youir intranet firewall的端口号被阻止,而不去代理服务器,您将无法访问POP邮件服务器。您需要与MIS人员交谈,了解如何使用代理服务器通过防火墙。
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;
    }
SmtpClient emailClient = new SmtpClient("mail.davincispainting.com", 25);