| 发表于:2007-04-04 11:02:475楼 得分:40 |
1. 校验下邮箱字符串是否合法。 2。去链接这个邮箱的服务器。 通常例如aaa@21cn.com 他的smtp服务器应该就是smtp.21cn.com,但不敢确认。 还有非smtp协议的服务器。例如http的hotmail 通常使用socket链接服务器的25端口, 他返回的应该是220 之后你发helo aaa@21cn.com\r\n 他返回的应该是250,如果不是250估计这个邮箱就是不存在了。 protected void send_cmd (string cmd,string oprnd){ send_cmd(cmd+ " "+oprnd); } protected void send_cmd(string cmd){ if(debug) system.out.println( "> > > "+cmd); os.print(cmd+ "\r\n "); } public void converse(string sender,string recipients,string subject,string body) /*throw smtpexception*/{ if(!expect_reply( "220 ")) die(/*ex_protocol*/4, "did not get smtp greeting "); send_cmd( "helo ", "madass@163.net "); if(!expect_reply( "250 ")) die(/*ex_protocol*/4, "did not get ack our helo "); send_cmd( "rset "); if(!expect_reply( "250 ")) die (/*ex_protocol*/4, "not reset "); send_cmd( "auth login "); if(!expect_reply( "334 ")) die (/*ex_protocol*/4, "not reset "); send_cmd(enc.encode(user.getbytes())); if(!expect_reply( "334 ")) die (/*ex_protocol*/4, "not reset "); send_cmd(enc.encode(psw.getbytes())); if(!expect_reply( "334 ")) die (/*ex_protocol*/4, "not reset "); | | |
|