我连smtp.163.com服务器,在WINFORM里面可以通过其发送mail到其他邮件服务器,但是在web上就不行,socket.Connect(host, port);在运行到这句时报错,错误信息如下:
System.Net.Sockets.SocketException: 请求的名称有效,但是没有找到请求的类型的数据。 at System.Net.Dns.GetHostByName(String hostName) at System.Net.Dns.Resolve(String hostName) at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port) ,
请各位大哥指点,谢谢

解决方案 »

  1.   

    Public void SendMail (MailMessage msg) 
    {
    NetworkStream nwstream = GetConnection (); 
    WriteToStream (ref nwstream, "EHLO"+ smtpHost + "\r\n"); 
    String welcomeMsg = ReadFromStream (ref nwstream); // implement HELO command if EHLO is orgnized. 
    if(IsUnknownCommand (welcomeMsg)) 
    {
    WriteToStream (ref nwstream, "HELO" +smtpHost + "\r\n"); } 
    CheckForError (welcomeMsg, ReplyConstants.OK); // Authentication is used if the u/p are supplied 
    AuthLogin (ref nwstream); WriteToStream (ref nwstream, "MAIL FROM: < "+ msg.From.Address +" >\r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.OK); SendRecipientList (ref nwstream, msg.To); 
    SendRecipientList (ref nwstream, msg.CC); 
    SendRecipientList (ref nwstream, msg.BCC); 
    WriteToStream (ref nwstream, "DATA\r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.START_INPUT); 
    If (msg.ReplyTo.Name! = null && msg.ReplyTo.Name.Length! = 0) 
    {
    WriteToStream (ref nwstream, "Reply-To: \ "" + msg.ReplyTo.Name + "\" < "+ msg.ReplyTo.Address +" >\r\n"); 

    else 
    {
    WriteToStream (ref nwstream, "Reply-To: < "+ msg.ReplyTo.Address +" >\r\n"); 

    if (msg.From.Name! = null && msg.From.Name.Length! = 0) 
    {
    WriteToStream (ref nwstream, "From: \ "" + msg.From.Name + "\" < "+ msg.From.Address +" >\r\n"); 

    else 
    {
    WriteToStream (ref nwstream, "From: < "+ msg.From.Address +" >\r\n"); 

    WriteToStream (ref nwstream, "To: "+ CreateAddressList (msg.To) +" \r\n"); 
    If (msg.CC.Count! = 0) 
    {
    WriteToStream (ref nwstream, "CC: "+ CreateAddressList (msg.CC) +" \r\n"); 

    WriteToStream (ref nwstream, "Subject: "+ msg.Subject +" \r\n"); 
    If (msg.Priority! = null) 
    {
    WriteToStream (ref nwstream, "X-Priority: "+ msg.Priority +" \r\n"); 

    if (msg.Headers.Count > 0) 
    {SendHeaders (ref nwstream,msg); 

    if (msg.Attachments.Count > 0 || msg.HtmlBody! = null) 
    {
    SendMessageBody (ref nwstream, msg); 

    else 
    {
    WriteToStream (ref nwstream, msg.Body + "\r\n"); 

    WriteToStream (ref nwstream, "\r\n. \r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.OK); 
    WriteToStream (ref nwstream, "QUIT\r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.QUIT); 
    CloseConnection (); 

    private bool AuthLogin (ref NetworkStream nwstream) 
    {if (username! = null && username.Length> 0 && password! = null && password.Length > 0) 
    {
    WriteToStream (ref nwstream, "AUTH LOGIN\r\n"); 
    If (AuthImplemented (ReadFromStream (ref nwstream))) 
    {
    WriteToStream (ref nwstream,Convert.ToBase64String (Encoding.ASCII.GetBytes (this.username.ToCharArray ())) + "\r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.SERVER_CHALLENGE); 
    WriteToStream (ref nwstream, Convert.ToBase64String (Encoding.ASCII.GetBytes (this.password.ToCharArray ())) + "\r\n"); 
    CheckForError (ReadFromStream (ref nwstream), ReplyConstants.AUTH_SUCCESSFUL); 
    Return true; 
    }

    return false; 
    }
      

  2.   

    cmd:
    telnet smtp.163.com 25
    ehlo www.163.com
    auth login
    [输入你的用户名]
    [输入你的密码]
    如果提示authentication successful.
    则可以:
    MAIL FROM
    RCPT TO
    ...
      

  3.   

    telnet smtp.163.com 25
    220 Coremail SMTP(Anti Spam) System (163com[20050206])
    ehlo www.163.com
    250-smtp10
    250-PIPELINING
    250-AUTH LOGIN PLAIN NTLM
    250-AUTH=LOGIN PLAIN NTLM
    250 8BITMIME
    auth login
    334 VXNlcm5hbWU6
    lover
    334 UGFzc3dvcmQ6
    lover
    535 CoremailSys:Error: authentication failed
    服务器太忙~