日期:2014-05-19  浏览次数:20827 次

jacob操作outlook
大家好,我想知道为explorer 里 除了outlook Selection(当前选中)还有哪些选项,比如所有的,比如未读的,已读的,删除的。草稿箱。 这些参数要怎么写,我怎么知道它里面有哪些参数? 跪求! 我很奇怪既然是固定参数为什么不定义一个常量类。


 ActiveXComponent xl = new ActiveXComponent("Outlook.Application");  
       
         Dispatch explorer = Dispatch.get(xl,"ActiveExplorer").toDispatch();  
         Dispatch selection = Dispatch.get(explorer, "Selection").toDispatch();  
         Variant count = Dispatch.get(selection, "Count");  
   
         for (int mailIndex = 1; mailIndex <= count.toInt(); mailIndex++ ) {  
             Dispatch mailItem = Dispatch.call(selection, "Item", new Variant(mailIndex)).toDispatch();  
   
             Variant senderName = Dispatch.get(mailItem, "SenderName");  
             Variant subject = Dispatch.get(mailItem, "Subject");  
             Variant body = Dispatch.get(mailItem, "HTMLBody");  
       
             String emailFileName = subject.toString() +".txt";    
               
             try {  
                 File email = new File(emailFileName);  
                 PrintWriter writer = new PrintWriter( new FileWriter(email) );  
                 writer.println("From: "+ senderName );  
                 writer.println("Subject: "+ subject);  
                 writer.println("");  
                 writer.print( body );  
                 writer.close();  
             }  
             catch (IOException e) {  
                 System.out.println("IOException writing e-mail with subject: '"+ subject +"'");