本文介绍了使用Outlook.com SMTP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Outlook.com smtp支持发送自动电子邮件.但是我得到以下异常:
I am trying to send an automated email using Outlook.com smtp support. However I am get the following exception:
System.Net.Mail.SmtpException: Failure sending mail.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host" Exception while sending email.
我的代码:
public bool SendEmail(MailMessage msg)
{
try
{
SmtpClient smtpClient = new SmtpClient("smtp-mail.outlook.com")
{
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("userAddress", "userPassword"),
Port = 587,
EnableSsl = true,
};
smtpClient.Send(msg);
msg.Dispose();
smtpClient.Dispose();
return true;
}
catch (Exception exp)
{
Console.WriteLine(exp.ToString());
return false;
}
}
推荐答案
我知道这是一个非常老的问题,我什至无法提供帮助,但是当我尝试使用发送电子邮件时遇到了类似的问题C#.
I know that this is an extremely old question and I might not even be able to help, however I had a similar problem when I tried to send an email using C#.
结果,我使用了它,使我可以发送电子邮件:
As a result I used this which allowed me to send the emails:
string _sender = "";
string _password = "";
SmtpClient client = new SmtpClient("smtp-mail.outlook.com");
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(_sender, _password);
client.EnableSsl = true;
client.Credentials = credentials;
MailMessage message = new MailMessage(_sender, "recipient of email");
message.Subject = "";
message.Body = "";
client.Send(message);
这可能对您不再有用,但是如果有人偶然发现了这个问题,至少有一个答案,其中包含有效的代码作为解决方案!
This probably will be of no use to you anymore, but in case anyone stumbles onto this question at least there is an answer which has working code acting as a fix!
这篇关于使用Outlook.com SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!