那要看server怎么设了, smtp中有个命令是vrfy, 你可以用它来判断用户(信箱地址)是否正确.
比如在test.com的smtp server上vrfy dureek, 如果存在[email protected]则通常返回一个真实的dureek在test.com上的email地址,反之则常常是的个user unkown的错误信息.

解决方案 »

  1.   

    我以前做PHP时曾对这个问题做过讨论。给你这篇文章吧。虽说是PHP的但是思路你可以参考一下,三级方法不过最后的方法实在太慢虽然准确。-------------------------电子邮件地址校验的方式探讨在应用程序中,我们经常要对用户输入的电子邮件地址进行校验,有避免一些无聊的人给一些错误的 email地址。校验的方法有很多种,本文从最基本的校验方式开始,对电子邮件地址校验方法做一个小结。
    1、用 Dreamweaver 3 生成的 javascript 脚本进行基本验证在 Behaviors | Validate Form | Accept Email Address 选项里对电子邮件地址输入的文本框进行校验。DW会自动生成一段相应的 javascript 代码,你可以修改其中的报错显示语句,比如改成中文。通过对其代码的分析,可以看出,它仅是简单地判断一下是否有 @ 字符。
    判断语句如下:p=val.indexOf('@');
    if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';因为程序是自动生成的,我就不给出源代码了。感兴趣的朋友可以自己试一下。象 fkdls@djfks@fjksldf 也可以通过检验。:)2、用正则表达式来验证是否是正确的 email地址这方面一般是采用 PHP 在服务器端进行校验,代码如下(来自PHP手册):<?php
    if (eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email)) {
      echo "您的 E-Mail 通过初步检查";
    }
    ?>其基本原理是检查输入的 E-Mail 字符串是否有 @ 字符,在 @ 字符前有英文字母或数字,在之后有数节字符串,最后的小数点后只能有二个或三个英文字母。新的 javascript 也提供了对正则表达式支持,所以我们也可以直接在客户端进行校验,而无需提交到服务器了。
    这样只需把上述php程序改成 javascript 程序就可。function CheckEmail(email) //给一个地址
    {  var pattern = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/;  if(pattern.test(str))  return true;  
    else  {  
       alert("请输入正确的email地址");  
       return false;  
    }  }  这种校验方法是我们最常用的,但也存在局限,比如, [email protected] 这种明显是不存在的地址也会被通过。
    3、用往 Socket 端口发送 SMTP 信息的方法来进行校验其实,我们还有一种比较麻烦但是更加严格的校验方式,就是利用 Socket 口往用户提供的信箱中发送 SMTP 指令。本方法用到的一些 SMTP 的常用指令,我就不给出说明了,有兴趣的朋友可以参考一下www.oso.com.cn的《用Socket发送电子邮件》一文或是读一些相关的资料。以下给出一个函数,来自《PHP程序设计》一书,它就是用这种方法来实现对 email地址的验证,不过我测试了一下,太慢了!如果我们把它简化一点,如只发一个 HELLO指令,不知可否?(我没试过)function validateEmail ($email){   
       global $SERVER_NAME;
       $return = array(false, "" );
       list ($user, $domain) = split("@", $email, 2);
       $arr = explode(".", $domain);   
       $count = count ($arr);
       $tld = $arr[$count - 2] . "." . $arr[$count - 1];
       if(checkdnsrr($tld, "MX")) {
          if(getmxrr($tld, $mxhosts, $weight)) {
             for($i = 0; $i < count($mxhosts); $i++){
                   $fp = fsockopen($mxhosts[$i], 25);
                if ($fp){
                   $s = 0;
                   $c = 0;
                   $out = "";
                   set_socket_blocking($fp, false);
                   do {
                      $out = fgets($fp, 2500);
                      if(ereg("^220", $out)){
                               $s = 0;
                         $out = "";
                         $c++;
                      }
                      else if(($c > 0) && ($out == "")){ 
                         break; 
                      }
                      else { 
                         $s++;
                      }
                      if($s == 9999) { 
                         break;
                      }
                   } while($out == "");
                   set_socket_blocking($fp, true);
                   fputs($fp, "HELO $SERVER_NAME\n");
                   $output = fgets ($fp, 2000);
                   fputs($fp, "MAIL FROM: <info@" . $tld . ">\n" );
                   $output = fgets($fp, 2000);
                   fputs($fp, "RCPT TO: <$email>\n");            
                   $output = fgets($fp, 2000);
                   if(ereg( "^250", $output )) {
                      $return[0] = true;
                   } 
                   else {
                      $return[0] = false;
                      $return[1] = $output;
                   }
                   fputs ($fp, "QUIT\n");
                   fclose($fp);
                   if($return[0] == true){ 
                      break; 
                   }
                }
             }
          }
       }
       return $return;
    }
    好了,如果我们结合第二和第三种方法,那么……… 嘿嘿!你就甭想耍我了。有什么问题,请与我联系 [email protected]
      

  2.   

    偶这里有一个用 c 写的,你把它改装一下吧。bool IsEmail(char *mail){
        static char *MAIL_POSTFIX
            = ".com.cn.net.cn.org.cn.gov.cn";
        static char *MAIL_INVALID
            = "`~!#$%^&*()+={}[]\\|:;\"\'<>,?/@";    int len = strlen(mail);
        char *start = mail;
        char *atpos = mail;
        char *end = mail + len - 1;    // [email protected] assume this is the shortest mail format.
        if (len < 7) return false;
        // the first character must not be '@'
        if (mail[0] == '@') return false;
        // it should not begin with digit
        if (mail[0] >= '0' && mail[0] <= '9') return false;
        mail = _strlwr(mail);
        while(*end != '.' && end > start) end--;
        // it's always must has a '.' pointer
        if (end <= start) return false;    // the end of the email part should in the MAIL_POSTFIX string
        int postlen = len - (end - mail);
        if (postlen == 4){
            // possiblely ends with .com, .net, .org etc..
            if (strstr(MAIL_POSTFIX, end) == NULL) return false;
        } else if (postlen == 3){
            // possiblely ends with ".cn", so check the second . part
            if ((end -= 4) <= mail) return false;
            if (strstr(MAIL_POSTFIX, end) == NULL) return false;
        } else {
            return false;
        }    while(*atpos != '@' && atpos != '\0') atpos++;
        // it's must always conatains '@' character
        if (*atpos != '@') return false;
        // the first character after '@' must not be '.'
        if (*(atpos + 1) == '.') return false;    // ok, let's check if it contains invalid characters
        // first check the string before the '@'
        for (start=mail;start<atpos;start++){
            if (Contains(MAIL_INVALID, *start)) return false;
        }
        // then check the string after the '@'
        for (start=atpos+1;start<end;start++){
            if (Contains(MAIL_INVALID, *start)) return false;
        }    // ok, it's just what i'm looking for so far.
        return true;
    }
      

  3.   

    这个子方法忘了发上来了:bool Contains(char *str, char ch){
        int len = strlen(str);
        for (int i=0;i<len;i++){
            if (str[i] == ch) return true;
        }    return false;
    }
      

  4.   

    to Dureek:
    你的命令在大多smtp服务器上同不过。
      

  5.   

    to golunch:
    主要是些比较大的smtp server ... 那是考虑到安全性才禁止这个命令的:p
      

  6.   


    To kiddycoffee(Kiddy):因为javascript已经支持正则表达式了,如果用这个方法来验证,实在没必要自己写函数在服务器端处理了。在服务器端要处理的就是发送信息给这个smtp,看它有什么反应,其实Dureek(普博)的方法也可以参考一下的,而我给的方法我自己都不想用,很慢的,用PHP的时候。