夢(mèng)幻之旅

          DEBUG - 天道酬勤

             :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評(píng)論 :: 0 Trackbacks
          package com.roadway.edserver.util;

          import java.util.HashMap;
          import java.util.Hashtable;
          import javax.naming.Context;
          import javax.naming.directory.Attribute;
          import javax.naming.directory.Attributes;
          import javax.naming.directory.DirContext;
          import javax.naming.directory.InitialDirContext;

          public class FetchSMTP {
              
          private static FetchSMTP smtpFetcher = new FetchSMTP();
              
          public static HashMap<String, String> smtps = new HashMap<String, String>();
              
          private FetchSMTP(){};
              
          public static FetchSMTP getInstance(){
                  
          return smtpFetcher;
              }

              
          private String getSmtpByAtBackside(String atBackside) {
                  String smtpServer 
          = null;
                  
          try {
                      Hashtable
          <String, String> env = new Hashtable<String, String>();
                      env.put(Context.INITIAL_CONTEXT_FACTORY,
          "com.sun.jndi.dns.DnsContextFactory");
                      DirContext ctx 
          = new InitialDirContext(env);
                      Attributes attrsAll 
          = ctx.getAttributes(atBackside);
                      Attribute attrMx 
          = attrsAll.get("MX");
                      String recordMx 
          = (String) attrMx.get();
                      smtpServer 
          = recordMx.substring(recordMx.indexOf(" "+ 1);
                  }
           catch (Exception e) {}
                  
          return smtpServer;
              }


              
          public String getSmtpByEmail(String email) {
                  String smtp 
          = null;
                  
          if (email != null ) {
                      String atBackside 
          = email.substring(email.indexOf("@"+ 1, email.length());
                      smtp 
          = smtps.get(atBackside);
                      
          if (smtp == null{
                          smtp 
          = this.getSmtpByAtBackside(atBackside);
                          
          if (smtp != null{
                              FetchSMTP.smtps.put(atBackside, smtp);
                          }

                      }

                  }

                  
          return smtp;
              }

              
          public static void main(String args[]){
                  FetchSMTP f 
          = FetchSMTP.getInstance();
                  System.out.println(f.getSmtpByEmail(
          "hwpok@163.com"));
              }

          }
          posted on 2008-01-12 20:51 HUIKK 閱讀(541) 評(píng)論(1)  編輯  收藏 所屬分類: Java

          評(píng)論

          # re: 跟據(jù)Email 查找 SMTP 服務(wù)器[未登錄] 2008-01-14 17:14 lucy
          完全看不懂呀  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 广元市| 宁武县| 洛宁县| 无为县| 乌拉特后旗| 玉树县| 甘孜| 峨眉山市| 晋江市| 恩施市| 宜章县| 江口县| 平乡县| 余江县| 鄄城县| 南城县| 浙江省| 阿坝县| 阆中市| 沐川县| 蓬莱市| 长丰县| 抚远县| 曲周县| 宜宾市| 平顶山市| 长岭县| 博湖县| 江陵县| 乌拉特前旗| 广河县| 新安县| 北川| 鄄城县| 运城市| 奉化市| 崇州市| 拜城县| 涞水县| 海淀区| 普陀区|