我得到了错误:
连接尝试失败,因为被连接方未 一段时间后正确响应或建立连接 由于连接的主机未能响应。 。 。* :25 < / p>
当我在服务器上发送邮件时。
我尝试了此解决方案,但仍然遇到相同的错误。
问题是线
服务器程序的IPAddress IP = IPAddress.Parse(ipStr);
应该是IPAddress IP = IPAddress.Any;
在这里,我创建了一个发送邮件的功能。
private static void SetUserCredentialAndProcessMail(MailMessage msg, string mailTo)
{
NetworkCredential networkCredential = new NetworkCredential(SendMail.userName, SendMail.password);
SmtpClient smtpClient = new SmtpClient(SendMail.smtpServer, SendMail.SmtpPort);
smtpClient.EnableSsl = SendMail.testMode == "1";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = (ICredentialsByHost)networkCredential;
try
{
MailMessage message = new MailMessage(SendMail.mailFrom, mailTo, msg.Subject, msg.Body);
message.IsBodyHtml = msg.IsBodyHtml;
if (msg.Attachments != null && msg.Attachments.Count > 0)
{
foreach (Attachment attachment in (Collection<Attachment>)msg.Attachments)
message.Attachments.Add(attachment);
}
smtpClient.Send(message);
}
catch (Exception ex)
{
throw ex;
}
}
这种错误的原因可能是什么.. ???