System.Net.Mail.SmtpException:
Failure sending mail. --->
System.Net.WebException:
Unable to connect to the remote server --->
System.Net.Sockets.SocketException:
No connection could be made because the target machine actively refused it xx.x.xx.xxx:25我的SMTP主机在IP地址之上,我无法收到邮件,它正在抛出上述异常。
下面是我的代码
mail.From = new MailAddress(email.From.EmailAddress,email.From.FullName);
mail.Subject = email.Subject;
mail.Body = email.Body;
if (email.Body.Contains("<html>"))
{
mail.IsBodyHtml = true;
}
if (!email.ExcludeAttachment && !string.IsNullOrEmpty(email.AttachmentPath))
mail.Attachments.Add(new Attachment(email.AttachmentPath));
client = new SmtpClient();
client.Host = ConfigurationSettings.AppSettings["SmtpServer"].ToString();
client.Send(mail);发布于 2015-09-04 07:28:12
最有可能的原因是您需要对服务器进行身份验证。您可能也需要发送身份验证,看看我的工作代码,看看是否可以调整它以满足您的需要。
也许还值得抓住Telrik Fiddler,看看smtp服务器上的响应是什么。
var client = new SmtpClient
{
Host = txtOutGoingServer.Text,
Port = Convert.ToInt16(txtServerPort.Text),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Password),
Timeout = 20000
};
try
{
m.To.Add(new MailAddress(dr[0].ToString().Trim()));
m.From = new MailAddress(txtUserName.Text);
foreach (var attachment in Attactments)
{
m.Attachments.Add(new Attachment(attachment));
}
client.Send(m);
m.To.Clear();
m.Attachments.Clear();
Success.Add(dr[0].ToString());
}
catch (SmtpException esException)
{
Errors.Add("Error sending to " + dr[0].ToString() + " " + esException.Message);
}
catch (Exception ex)
{
Errors.Add("Error sending to " + dr[0].ToString() + " " + ex.Message);
}使用此工作代码的方法是循环遍历电子邮件地址和联系人名称的数据表,因此只需替换dr[].ToString().无论你的价值观是什么。
https://stackoverflow.com/questions/32391850
复制相似问题