获取邮箱服务器地址

编写代码

private static final String DNS = "dns://";
    public static void main(String[] args) throws Exception{
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
        env.put(Context.PROVIDER_URL, DNS);

        InitialDirContext ctx = new InitialDirContext(env);
        Attributes attributes = ctx.getAttributes("qq.com", new String[]{"MX"});
        System.out.println(attributes );
    }

结果如下
获取邮箱服务器地址

相关推荐