本地发送一切正常,能够发送成功!
上传到服务器上后就出现了这种问题!(PS:服务器只是租的一个虚拟空间。)
异常信息如下:
(高手速来帮小弟看看!谢谢!)System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 74.125.53.109:25   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)   --- End of inner exception stack trace ---   at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)   at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)   at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)   at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)   at System.Net.Mail.SmtpClient.GetConnection()   at System.Net.Mail.SmtpClient.Send(MailMessage message)   --- End of inner exception stack trace ---   at System.Net.Mail.SmtpClient.Send(MailMessage message)   at SendMail.ProcessRequest(HttpContext context)

解决方案 »

  1.   

    string strMailFrom = ConfigurationManager.AppSettings["mailFrom"];
                string strMailFromPass = ConfigurationManager.AppSettings["MailFromPass"];
                string strSmtpServer = ConfigurationManager.AppSettings["SmtpServer"];
                SmtpClient client = new SmtpClient(strSmtpServer); //邮件发送类
                client.UseDefaultCredentials = false;             client.Credentials = new NetworkCredential(strMailFrom, strMailFromPass);            client.EnableSsl = true;
                
                client.DeliveryMethod = SmtpDeliveryMethod.Network;            string strSubject = string.Empty;
                System.Text.StringBuilder strBody = new System.Text.StringBuilder();            strBody.Append("From:&nbsp;&nbsp;" + context.Request["frm_name"] + "&nbsp;&nbsp;&nbsp;<br />");
                strBody.Append("EMail:&nbsp;&nbsp;" + context.Request["frm_email"] + "&nbsp;&nbsp;&nbsp;<br />");
                //strBody.Append("Subject:&nbsp;&nbsp;" + context.Request["frm_subject"] + "&nbsp;&nbsp;&nbsp;<br />");
                strSubject = context.Request["frm_subject"];
                strBody.Append("Message:&nbsp;&nbsp;" + context.Request["frm_message"] + "&nbsp;&nbsp;&nbsp;<br />");            MailMessage message = null;
                message = new MailMessage(strMailFrom, strMailTo, strSubject, strBody.ToString());            message.BodyEncoding = System.Text.Encoding.UTF8; 
                message.IsBodyHtml = true;
                try
                {
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.ToString());
                }
      

  2.   

    http://blog.csdn.net/andrew_wx/article/details/6950555
    这里面有一个,参考参考。
      

  3.   

    [Quote=引用 7 楼 wbloveilove 的回复:]
    引用 5 楼 vincent_void 的回复:帮博哥顶贴啊!
    人气,,人气呢?操,别发这种没营养的文字好吧
    [/Quote
    蛋疼。
      

  4.   

    试试这个。。        /// <summary>
            /// 用于发邮件的方法
            /// </summary>
            /// <param name="username">显示的发件人名称</param>
            /// <param name="subject">显示的主题名称</param>
            /// <param name="toname">收件人邮箱号码</param>
            /// <param name="body">内容</param>
            public static void SendMessage(string username, string subject, string toname, string body)
            {
                MailAddress from = new MailAddress("[email protected]", username);
                MailMessage mail = new MailMessage();
                mail.Subject = subject;
                mail.From = from;
                //设置邮件的收件人
                string address = "";
                string displayName = "";            string[] mailNames = (toname + ";").Split(';');
                foreach (string name in mailNames)
                {
                    if (name != string.Empty)
                    {
                        if (name.IndexOf('<') > 0)
                        {
                            displayName = name.Substring(0, name.IndexOf('<'));
                            address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
                        }
                        else
                        {
                            displayName = string.Empty;
                            address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
                        }
                        mail.To.Add(new MailAddress(address, displayName));
                    }
                }
                //设置邮件的内容
                mail.Body = body;
                //设置邮件的格式
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml = true;
                //设置邮件的发送级别
                mail.Priority = MailPriority.Normal;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                SmtpClient client = new SmtpClient();
                //设置用于 SMTP 事务的主机的名称,填IP地址也可以了
                client.Host = "smtp.163.com";
                //设置用于 SMTP 事务的端口,默认的是 25
                //client.Port = 25;
                client.UseDefaultCredentials = false;
                //这里才是真正的邮箱登陆名和密码,比如我的邮箱地址是 hbgx@hotmail, 我的用户名为 hbgx ,我的密码是 xgbh
                client.Credentials = new System.Net.NetworkCredential("邮箱帐号", "密码");
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                //都定义完了,正式发送了,很是简单吧!
                client.Send(mail);
            }
      

  5.   

    建议看下我的一篇文章
    http://blog.csdn.net/keymo_
    其中的“学习笔记37”   
      

  6.   

    你telnet一下邮件服务器25端口,或者用outlook试着发送一下邮件
      

  7.   

    服务器是租的虚拟空间,连远程桌面都没有,只有ftp。
      

  8.   

    System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 74.125.53.109:25口译:系统.NET WEB异常:未能链接远程服务器——》.NET Sockets异常:尝试链接失败,原因是因为在特定时间内未能取得响应,或者设置的链接因为未能取得74.125.53.109:25的主机响应我的理解是:你的虚拟空间FTP不能使用主机服务器的SMTP服务,不能与主机进行通信导致的。联系服务提供商吧!
      

  9.   

    System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server --->ping下来远程服务器。看看连接是不是正常,然后用 telnet xxx.xxx.xxx.xxx 端口 看看这样能不能连接邮件服务器。