关于验证用户输入的email地址真实问题

1,思路就是以@把用户名,与域名分开。

先域名验证,后在域上找用户。


 /***
  * 域存在验证
  *@param DN
  *@return true 表示存在,false 表示不存在;
  *May 21, 2010 by xxx
  */
 public static boolean checkDn(String DN) {
  Hashtable env = new Hashtable();
  env.put("java.naming.factory.initial",
    "com.sun.jndi.dns.DnsContextFactory");
  DirContext ictx = null;
  try {
   ictx = new InitialDirContext(env);
  } catch (NamingException e1) {
   e1.printStackTrace();
  }
  Attributes attrs = null;
  try {
   attrs = ictx.getAttributes(DN, new String[] { "TXT" });
   /** TXT RFC 1035 上有定义* */
   return true;
  } catch (NamingException e) {
   System.out.println(e.toString());
   return false;
  }
 }

 

然后用户名怎么验证呢,网上说

vrfy  username

资料如下

VRFY -- Verifies the existence and user name of a given mail address. This command is not implemented in all mail servers. And it can be blocked by firewalls.

 

 

Every command will receive a reply from the mail server in the form of a three digit number followed by some text describing the reply. For example,

250 OK

or

500 Syntax error, command unrecognized.

 

实际上好多服务器为了安全期间,屏蔽了vrfy命令,还有这个命令可能被firewalls挡住。所以这个可用性不行。

 

还有一个可用的命令是

RCPT TO:< XXX@XXX.XX >

但这个命令是如何说的呢

The RCPT Command

 

You tell the mail server who the recipient of your message is by using the RCPT command. You can send more than one RCPT command for multiple recipients. The server will respond with a code of 250 to each command. The syntax for the RCPT is:

RCPT TO:<forward-path>

 

Only one recipient can be named per RCPT command. If the recipient is not known to the mail server, the response code will be 550. You might also get a response code indicating that the recipient is not local to the server. If that is the case, you will get one of two responses back from the server:

  • 251 User not local; will forward to <forward-path>-This reply means that the server will forward the message. The correct mail address is returned so that you can store it for future use.
  • 551 User not local; please try <forward-path>-This reply means that the server won't forward the message. You need to issue another RCPT command with the new address.

这个命令是你用来告诉服务器,你的信息接收人是谁,当然你可以发送这个命令多次,服务器会为每个这样的命令返回250这人返回号,当然它不是在说你是250。

假如邮件服务器不知道这个接收着,它会返回550回应号,你也可能收到251,和551这要的返回号,收到251返回号,说明,这个接收着,服务器不知道,但它正在从mx中找,不一定不存在呀,你等等再说,要是返回551说明服务器不知道这个接收着,并不再从mx找这个接收着,表示就此结束。

这些都要根据服务器的设置有关。

 

用这个命令照理说是可行的,因为假如邮件服务器不知道这个接收着,它会返回550回应号,要么就知道,关键是你要收到251怎么办呢,你说是有这个用户,还是没有呢,因为251表示,服务器正在为你寻找,可能半小时后出结果,半小时用户可等不那么长时间。

 

看来,实际上要做到每个邮件地址都能快速验证,照这样看来,是不可能的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值