【问题标题】:Error when trying to send mails using smtp尝试使用 smtp 发送邮件时出错
【发布时间】:2013-08-22 15:10:57
【问题描述】:

当我尝试使用 smtp 发送消息时收到以下错误消息。

连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应 67.69.240.69:25 System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机未能响应 67.69.240.69:25 在 System.Net.Sockets.Socket.DoConnect(端点 endPointSnapshot,SocketAddress 套接字地址) 在 System.Net.ServicePoint.ConnectSocketInternal(布尔连接失败、套接字 s4、套接字 s6、套接字和套接字、IPAddress 和地址、ConnectSocketState 状态、IAsyncResult asyncResult、Int32 超时、异常和异常) --- 内部异常堆栈跟踪结束 --- 在 System.Net.ServicePoint.GetConnection(PooledStream PooledStream,对象所有者,布尔异步,IPAddress& 地址,Socket& abortSocket,Socket& abortSocket6,Int32 超时) 在 System.Net.PooledStream.Activate(对象 owningObject,布尔异步,Int32 超时,GeneralAsyncDelegate asyncCallback) 在 System.Net.PooledStream.Activate(对象拥有对象,GeneralAsyncDelegate asyncCallback) 在 System.Net.ConnectionPool.GetConnection(对象 owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout) 在 System.Net.Mail.SmtpConnection.GetConnection(字符串主机,Int32 端口) 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息) 在 Handler.BLL.cSendMail.SendMail(字符串 p_strFrom,字符串 p_strDisplayName,字符串 p_strTo,字符串 p_strSubject,字符串 p_strMessage,字符串 strFileName) [staffID:,21/08/2013 9:49:34 AM]:状态代码:GeneralFailure

代码

   public bool SendMail(string p_strFrom, string p_strDisplayName, string p_strTo, string p_strSubject, string p_strMessage , string strFileName)
 {
     try
     {
         p_strDisplayName = _DisplayName;
         string smtpserver = _SmtpServer;
         SmtpClient smtpClient = new SmtpClient();
         MailMessage message = new MailMessage();
         MailAddress fromAddress = new MailAddress(_From,_DisplayName);
         smtpClient.Host = _SmtpServer;
         smtpClient.Port = Convert.ToInt32(_Port);
         string strAuth_UserName = _UserName;
         string strAuth_Password = _Password;
         if (strAuth_UserName != null)
         {
             System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(strAuth_UserName, strAuth_Password);
             smtpClient.UseDefaultCredentials = false;
             if (_SSL)
             {
                 smtpClient.EnableSsl = true;
             }
             smtpClient.Credentials = SMTPUserInfo;
         }
         message.From = fromAddress;

         message.Subject = p_strSubject;
         message.IsBodyHtml = true;
         message.Body = p_strMessage;
         message.To.Add(p_strTo);
         try
         {
             smtpClient.Send(message);
             Log.WriteSpecialLog("smtpClient mail sending first try success", "");
         }
          catch (Exception ee)
         {
             Log.WriteSpecialLog("smtpClient mail sending first try Failed : " + ee.ToString(), "");
             return false;
         }
         return true;
     }
     catch (Exception ex)
     {
         Log.WriteLog("smtpClient mail sending overall failed : " + ex.ToString());  
         return false;
     }
 }

当 3 封或更多邮件只发送一两封失败时

【问题讨论】:

  • 粘贴代码怎么样

标签: c# smtp


【解决方案1】:

我认为这与您的端口设置

有关

尝试设置你的Port to 587 而不是port 25,也看看this

【讨论】:

  • 我用的是smtp10.on.aibn.com服务器,可以设置587吗?
【解决方案2】:

一旦我陷入同样的​​错误,发现端口 25 被我安装在系统中的防病毒软件阻止。我只是禁用了它。 如果您的 smtp 托管在其他机器上或者它是第三方托管,那么您必须澄清端口 25 是否被解锁。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 2022-01-18
    • 2015-03-05
    • 2016-08-25
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多