c# - 连接尝试失败 HRESULT 异常 : 0x8007274C

标签 c#

我尝试通过网络向 Yahoo 邮件帐户发送邮件,并且在前一天运行良好。今天,当我在没有任何更改的情况下运行相同的代码(但使用不同的网络连接)时,显示以下错误。

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. (Exception from HRESULT: 0x8007274C)  

我了解到错误是由于连接超时。我检查了 Allow network loopback 属性,但仍显示错误。
有什么办法可以解决吗?

为什么它运行了一次,现在却不运行了?

使用 System.Threading.Tasks; 使用 EASendMailRT;

private async void buttonSend_Click(object sender, RoutedEventArgs e)  
          {
              buttonSend.IsEnabled = false;  
              await Send_Email();  
              buttonSend.IsEnabled = true;  
          }  
          private async Task Send_Email()  
          {
              string Result = "";  
              try  
              {  
              SmtpMail oMail = new SmtpMail("TryIt");  
              SmtpClient oSmtp = new SmtpClient();  

            // Set sender email address, please change it to yours
              oMail.From = new MailAddress("apple@yahoo.com");  

            // Add recipient email address, please change it to yours
            oMail.To.Add(new MailAddress("banana@yahoo.com"));

            // Set email subject and email body text
              oMail.Subject = "Subject entered";
              oMail.TextBody = "body of mail";  

              // Your SMTP server address  
              SmtpServer oServer = new SmtpServer("smtp.mail.yahoo.com");  

              // User and password for SMTP authentication              
              oServer.User = "apple@yahoo.com";    
              oServer.Password = "testpassword";  
              //yahoomail requires TLS/SSL and SMTP port is 465
              // If your SMTP server requires TLS connection on 25 port, please add this line    
              //oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;  

              // If your SMTP server requires SSL connection on 465 port, please add this line  
              oServer.Port = 465;  
              oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;  

              await oSmtp.SendMailAsync(oServer, oMail);  
              Result = "Email was sent";  
          }  
          catch (Exception ep)  
          {
              Result = String.Format("Failed to send email with the following error: {0}", ep.Message);  
          }  

          // Display Result by Diaglog box  
          Windows.UI.Popups.MessageDialog dlg = new  
              Windows.UI.Popups.MessageDialog(Result);  

          await dlg.ShowAsync();  
      }  

最佳答案

我之前遇到过这种情况,当时我的防病毒软件认为未知/未签名的进程正在尝试发送电子邮件。尝试关闭您的 A/V 或防火墙一分钟,然后重试。

关于c# - 连接尝试失败 HRESULT 异常 : 0x8007274C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23862696/

相关文章:

c# - 如何通过文本获取 ListView 项的索引

c# - AsEnumerable().Take

c# - 使用 sp_help_job 在 C# 中检查 SQL 作业状态

c# - 一个类有一个与它自己的类型相同的字段/属性吗?

c# - 从数据库获取标志并在身份验证中设置

c# - Visual Studio winform设计器将设计错误显示为文本而不是html

c# - 无法在 Xamarin 中安装 SQLite-Net-pcl

c# - MvxException : Failed to construct and initialize ViewModel

c# - 这里的 Actor 在哪里? LINQ to Entities 仅支持转换实体数据模型基元类型

c# - Visual C# 使用链接将项目添加到 contextMenuStrip