我在Arvixe工作多年,最近他们改变了所有权并进行了各种迁移。他们的许多客户都有问题。
这是ASP.NET 4.5 Web应用程序
自从他们迁移以来,我的网站用户尝试通过表单发送电子邮件时遇到异常: http://goo.gl/zz7FeH
消息“无法连接到远程服务器”
InnerException {“连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应104.27.186.185:25”} System.Exception {System.Net。 Sockets.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 :(得分:0)
...能够连接:telnet smtp.davincispainting.com 25
但是在你的代码中:
SmtpClient emailClient = new SmtpClient("mail.davincispainting.com", 25);
您在此处使用可解析为不同IP地址的不同主机:smtp.xxx解析为143.95.251.2,而mail.xxx解析为104.27.186.185。并且在第一个工作时连接到端口25,而在第二个工作时不连接。