直连其它邮件服务器的方式,需要使用DNS解析邮件服务器的域名
/**
* DNS解析域名
* @return String 返回解析后的邮件服务器地址
* @throws Exception 异常
*/
public MialList<String> parseInetAddress(String domain) throws Exception
{
MialList<String> mailList = new MialList<String>();
String dns = "dns:";
String smtpHost = "";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
env.put(Context.PROVIDER_URL, dns);
DirContext dir = new InitialDirContext(env);
Attributes atts = dir.getAttributes(domain, new String[] {"MX"});
if (null == atts || atts.size() <= 0)
{
RunLogger.debug("error:",
"Your dns server does not have a corresponding MX record!");
throw new java.lang.IllegalStateException();
}
NamingEnumeration servers = atts.getAll();
while (servers.hasMore())
{
Attribute att = (Attribute)servers.next();
for (int i = 0; i < att.size(); i++)
{
smtpHost = (String)att.get(i);
smtpHost = smtpHost.substring(smtpHost.indexOf(" ") + 1);
RunLogger.debug("smtpHost:", smtpHost);
mailList.add(smtpHost);
}
}
return mailList;
}
帖子73 精华1 积分204 威望33 金钱0 贡献25 激情63 休闲18 查看详细资料
编辑 引用 TOP
/**
* DNS解析域名
* @return String 返回解析后的邮件服务器地址
* @throws Exception 异常
*/
public MialList<String> parseInetAddress(String domain) throws Exception
{
MialList<String> mailList = new MialList<String>();
String dns = "dns:";
String smtpHost = "";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
env.put(Context.PROVIDER_URL, dns);
DirContext dir = new InitialDirContext(env);
Attributes atts = dir.getAttributes(domain, new String[] {"MX"});
if (null == atts || atts.size() <= 0)
{
RunLogger.debug("error:",
"Your dns server does not have a corresponding MX record!");
throw new java.lang.IllegalStateException();
}
NamingEnumeration servers = atts.getAll();
while (servers.hasMore())
{
Attribute att = (Attribute)servers.next();
for (int i = 0; i < att.size(); i++)
{
smtpHost = (String)att.get(i);
smtpHost = smtpHost.substring(smtpHost.indexOf(" ") + 1);
RunLogger.debug("smtpHost:", smtpHost);
mailList.add(smtpHost);
}
}
return mailList;
}
帖子73 精华1 积分204 威望33 金钱0 贡献25 激情63 休闲18 查看详细资料
编辑 引用 TOP