【发布时间】:2013-05-27 15:31:48
【问题描述】:
我正在尝试使用以下方法发送电子邮件。为了安全起见,此处未提供凭据。但他们是正确的。
static void Main(string[] args)
{
string mailTo = "testmail@testmail.com";
MailMessage mail = new MailMessage("email@email.onmicrosoft.com", mailTo);
mail.Subject = "Test";
mail.Body = "Blank Email";
mail.Priority = MailPriority.High;
mail.IsBodyHtml = true;
// Set the StmpServer name.
SmtpClient mailSmtp = new SmtpClient("Smtp.mail.microsoftonline.com");
// Smtp configuration
mailSmtp.Credentials = new System.Net.NetworkCredential("email@email.onmicrosoft.com", "********");
mailSmtp.Port = 587;
mailSmtp.Timeout = 30000;
try
{
mailSmtp.Send(mail);
}
catch(Exception ex) {
Console.WriteLine(ex.Message.ToString());
}
}
但这不起作用。 “Failur sent mail”是SmtpException捕获的消息。
我在设置凭据之前尝试过使用mailSmtp.UseDefaultCredentials = false;。 EnableSsl 到 true,Deliverymethod 到 Network。但一切都没有改变这种情况。
【问题讨论】:
-
错误信息仅此而已?
-
我在 InnerException 中收到了这条消息。
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 65.55.171.153:587 -
在此处提供更多异常详情。
-
'无法连接到远程服务器' ... SocketErrorCode =
System.Net.Sockets.SocketError.TimedOutNativeErrorCode =10060
标签: c# email smtpclient