获取邮箱服务器地址

7次阅读

共计 411 个字符,预计需要花费 2 分钟才能阅读完成。

编写代码

    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);
    }

结果如下

正文完
 0