Jacob

 1 import com.jacob.activeX.ActiveXComponent;
 2 import com.jacob.com.Dispatch;
 3 
 4 public class Util {
 5     public static void sendEmail(Map<String, String> unfinished) {
 6      // System.out.println(System.getProperty("java.library.path"));
 7         Map<String, String> recipientMAP = initialProperties("recipient");
 8         StringBuffer sb = new StringBuffer();
 9         ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
10         Dispatch mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
11         Dispatch recipients = Dispatch.call(mailItem, "Recipients").getDispatch();
12         Iterator<Entry<String, String>> recipient = recipientMAP.entrySet().iterator();
13         while (recipient.hasNext()){
14             Entry<String, String> entry = recipient.next();
15             String address = entry.getValue();
16             Dispatch.call(recipients, "Add", address);
17         }
18         Dispatch.put(mailItem, "Subject", "TRS Weekly Checking");
19         if (unfinished.isEmpty()) {
20             sb.append("<h1>All members have completed TRS for this week. <br>Thanks all!</h1>");
21         } else {
22             sb.append("<h1>Hi guys, <br>Please book your TRS for this week:</h1>");
23             sb.append("<table style='color:red; font-size:12pt' border='1' cellspacing='0' cellpadding='5'><tr><th>Name</th><th>SOEID</th></tr>");
24             Iterator<Entry<String, String>> iter = unfinished.entrySet().iterator();
25             while (iter.hasNext()) {
26                 Entry<String, String> entry = iter.next();
27                 sb.append("<tr><td>" + entry.getValue() + "</td><td>" + entry.getKey() + "</td></tr>");
28             }
29             sb.append("</table>");
30         }
31         String body = "<html><body>" + sb.toString() + "</body></html>";
32         Dispatch.put(mailItem, "HTMLBody", body);
33         Dispatch.call(mailItem, "Display");
34         Dispatch.call(mailItem, "Send");
35         System.out.println("The mail was sent out.");
36     }
37 }
View Code

 通过 JACOB 实现 Java 与 COM 组件的互操作 http://www.ibm.com/developerworks/cn/java/j-lo-jacob/ JACOB is a JAVA-COM Bridge that allows you to call COM Automation comp http://sourceforge.net/projects/jacob-project/

原文地址:https://www.cnblogs.com/JulyLeo/p/3178512.html