java调用outlook word (使用JaCod开源框架)

package test;   
import java.io.BufferedReader;   
  
public class TestMail {   
  
    public static void main(String[] args) throws Exception {   
        /*String body = "<div style='color:red;'>This is a Test !</div>";  
        Runtime.getRuntime().exec("D:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.EXE  mailto:KO@techson.com.hk?subject=Chinese New Year backup arrangement" +  
                "&cc=Ko@techson.com.hk&body="+body);*/  
           
        //System.out.println(System.getProperty("java.library.path"));     
           
           ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");     
           //Dispatch ds = axOutlook.getObject();   
          /* Dispatch namespace = Dispatch.call(axOutlook, "GetNamespace", "MAPI").toDispatch() ;  
           String path = new File("F:/test.htm").getAbsolutePath();   
           Dispatch mailItem = Dispatch.call(namespace, "OpenSharedItem", path).toDispatch(); */  
              
              
           Dispatch mailItem = Dispatch.call(axOutlook, "CreateItem", 0).getDispatch();     
              
           //Dispatch mailItem = Dispatch.call(axOutlook, "Open", "F:/test.htm").toDispatch();   
          // Dispatch body = Dispatch.call(mailItem, "Body").getDispatch();;     
          // Dispatch.call(body, "Copy");   
              
           Dispatch inspector = Dispatch.get(mailItem, "GetInspector").getDispatch();   
  
           //收件人     
           Dispatch recipients = Dispatch.call(mailItem, "Recipients").getDispatch();     
           Dispatch.call(recipients, "Add" , "crycbj@163.com");     
           //邮件主题     
           Dispatch.put(mailItem, "Subject", "Test5!");     
           Dispatch.put(mailItem, "CC", "1023865645@qq.com");     
           //Dispatch.put(mailItem, "CC", "crycbj@163.com");     
           //Dispatch.put(mailItem, "ReadReceiptRequested", "false");    
              
           String body = "<html><body><div style='color:red;'>This is a Test !</div></body></html>";   
           //Dispatch.put(mailItem, "HTMLBody", body);    
              
          // File file = new File("C:/test.htm");   
//         FileOutputStream f = new FileOutputStream("F:/test.htm");   
//         f.write(body.getBytes());   
//         f.close();   
              
           BufferedReader bf = new BufferedReader(new FileReader(new File("F:/Ro.htm")));   
           String html = "";   
           String str = "";   
           while( (str=bf.readLine()) != null){   
               html += str;   
           }   
           Dispatch.put(mailItem, "HTMLBody", html);    
              
           //Dispatch bodyDis = Dispatch.get(mailItem, "Body").toDispatch();     
           //Dispatch.call(bodyDis, "Add" , "F:/test.htm");     
           //Dispatch.put(mailItem, "Body", new Variant("F:/test.htm"));     
              
           //Dispatch.put(mailItem, "Body", body);     
           //Dispatch.call(mailItem, "InsertAfter",body );//插入一个段落   
              
           //Dispatch selection = Dispatch.get(axOutlook, "Selection").toDispatch();   
              
           //Dispatch inHtmleditor = Dispatch.call(inspector, "HTMLEditor").getDispatch();   
          // Dispatch.call(inHtmleditor, "Paste").getDispatch();     
           //Dispatch.invoke(inHtmleditor, "Paste", Dispatch.Method, new Object[]{false}, new Variant(false));   
              
           //附件     
//             Dispatch attachments = Dispatch.call(mailItem, "Attachments").getDispatch();     
//             Dispatch.call(attachments, "Add" , "D:\\20110127.txt");     
//             Dispatch.call(attachments, "Add" , "D:\\20110128.txt");     
           //显示新邮件窗口     
              
           Dispatch.call(mailItem, "Display");     
           Dispatch.call(mailItem, "Send");     
              
              
    }   
}  
源码请参考:http://sourceforge.net/projects/jacob-project/ 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值