Jacob - Outlook

时间:2022-10-25 03:51:16
 import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch; public class Util {
public static void sendEmail(Map<String, String> unfinished) {
// System.out.println(System.getProperty("java.library.path"));
Map<String, String> recipientMAP = initialProperties("recipient");
StringBuffer sb = new StringBuffer();
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
Dispatch recipients = Dispatch.call(mailItem, "Recipients").getDispatch();
Iterator<Entry<String, String>> recipient = recipientMAP.entrySet().iterator();
while (recipient.hasNext()){
Entry<String, String> entry = recipient.next();
String address = entry.getValue();
Dispatch.call(recipients, "Add", address);
}
Dispatch.put(mailItem, "Subject", "TRS Weekly Checking");
if (unfinished.isEmpty()) {
sb.append("<h1>All members have completed TRS for this week. <br>Thanks all!</h1>");
} else {
sb.append("<h1>Hi guys, <br>Please book your TRS for this week:</h1>");
sb.append("<table style='color:red; font-size:12pt' border='1' cellspacing='0' cellpadding='5'><tr><th>Name</th><th>SOEID</th></tr>");
Iterator<Entry<String, String>> iter = unfinished.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, String> entry = iter.next();
sb.append("<tr><td>" + entry.getValue() + "</td><td>" + entry.getKey() + "</td></tr>");
}
sb.append("</table>");
}
String body = "<html><body>" + sb.toString() + "</body></html>";
Dispatch.put(mailItem, "HTMLBody", body);
Dispatch.call(mailItem, "Display");
Dispatch.call(mailItem, "Send");
System.out.println("The mail was sent out.");
}
}

通过 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/