日期:2014-05-18  浏览次数:20595 次

本机可以,放到服务器就不能发邮件了
我做了一个发邮件的功能,在本机上测试是成功的,但放到服务器上就出错,实在是太奇怪了。
我把部分代码帖出来,大家帮忙看看哈

发邮件的代码:
  string   s_from   =   "test@163.com ";
                string   s_to   =   "testto@163.com ";
                string   pwd   =   "520 ";
                string   s_body   =   "test ";
             
                int   i   =   s_from.IndexOf( "@ ");
                string   username   =   s_from.Substring(0,   i);


                MailAddress   from   =   new   MailAddress(s_from);
                MailAddress   to   =   new   MailAddress(s_to);
                MailMessage   mailobj   =   new   MailMessage(from,   to);
                mailobj.Subject   =   "subject ";
                mailobj.Body   =   s_body;
                mailobj.IsBodyHtml   =   true;
                mailobj.BodyEncoding   =   System.Text.Encoding.GetEncoding( "GB2312 ");
                mailobj.Priority   =   MailPriority.High;
       
               
                mailobj.Attachments.Add(new   Attachment(@ "E:\JBS\pdf\5dc48cb9-8751-44a1-880f-91e8dfbce164.pdf   "));
                SmtpClient   smtp   =   new   SmtpClient( "smtp.163.com ");
                //   smtp.Host   =   "smtp.163.com ";
                smtp.UseDefaultCredentials   =   false;
                smtp.Credentials   =   new   NetworkCredential(username,   pwd);
                smtp.DeliveryMethod   =   SmtpDeliveryMethod.Network;

smtp.Send(mailobj);
-----------------------
错误提示:
System.Net.Mail.SmtpException:   Failure   sending   mail.   --->   System.FormatException:   Smtp   server   returned   an   invalid   response.   at   System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[]   buffer,   Int32   offset,   Int32   read,   Boolean   readLine)   at   System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader   caller,   Boolean   oneLine)   at   System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader   caller)   at   System.Net.Mail.SmtpReplyReader.ReadLine()   at   System.Net.Mail.CheckCommand.Send(SmtpConnection   conn,   String&   response)   at   System.Net.Mail.DataCommand.Send(SmtpConnection   conn)   at   System.Net.Mail.Smt