日期:2014-05-20 浏览次数:20835 次
// DNS服务器,看看本机的DNS配置 String dns = "dns://192.168.0.1"; String email = "xxx@msn.com"; if(args.length>0) email = args[0]; String domain = email.substring(email.indexOf('@')+1); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); env.put(Context.PROVIDER_URL, dns); DirContext ctx = new InitialDirContext(env); Attributes attr = ctx.getAttributes(domain, new String[]{"MX" }); NamingEnumeration servers = attr.getAll(); // 列出所有邮件服务器: while(servers.hasMore()) { Attribute hosts = (Attribute)servers.next(); for(int i=0;i<hosts.size();i++){ String host = (String)hosts.get(i); host = host.substring(host.indexOf(' ')+1); System.out.print("Send mail to " + host + " ..."); sendMail(host, email); System.out.println("OK"); } }