В настоящее время я пытаюсь настроить модуль в своем приложении Java для отправки запланированных электронных писем (в частности, отчетов jasper) с использованием MS Outlook 2007, я нашел этот учебник для eclipse http://www.vogella.com/tutorials/EclipseMicrosoftIntegration/article.html, и я загрузил упомянутые библиотеки (swt.jar, swt-debug.jar и org.eclipse.core.commands.jar для x64bits) и добавил их в путь к классам моего проекта Netbeans. Я скопировал код с этой страницы, чтобы попробовать
public class SendMail{
public static void main(String[] args) {
SendMail outlook = new SendMail();
try {
outlook.execute();
} catch (ExecutionException ex) {
Logger.getLogger(SendMail.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Object execute() throws ExecutionException {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
// This should start outlook if it is not running yet
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// now get the outlook application
OleClientSite site2 = new OleClientSite(frame, SWT.NONE,
"Outlook.Application");
OleAutomation outlook = new OleAutomation(site2);
//
OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */)
.getAutomation();
setProperty(mail, "To", "[email protected]"); /*
* Empty but could also be
* predefined
*/
setProperty(mail, "Bcc", "[email protected]"); /*
* Empty but could also be
* predefined
*/
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", "Top News for you");
setProperty(mail, "HtmlBody",
"<html>Hello<p>, please find some infos here.</html>");
File file = new File("c:/temp/test.txt");
if (file.exists()) {
OleAutomation attachments = getProperty(mail, "Attachments");
invoke(attachments, "Add", "c:/temp/test.txt");
} else {
JOptionPane.showMessageDialog(null, "Info.",
"Attachment not found; will send email with attachment", JOptionPane.QUESTION_MESSAGE);
}
invoke(mail, "Display" /* or "Send" */);
return null;
}
private static OleAutomation getProperty(OleAutomation auto, String name) {
Variant varResult = auto.getProperty(property(auto, name));
if (varResult != null && varResult.getType() != OLE.VT_EMPTY) {
OleAutomation result = varResult.getAutomation();
varResult.dispose();
return result;
}
return null;
}
private static Variant invoke(OleAutomation auto, String command,
String value) {
return auto.invoke(property(auto, command),
new Variant[]{new Variant(value)});
}
private static Variant invoke(OleAutomation auto, String command) {
return auto.invoke(property(auto, command));
}
private static Variant invoke(OleAutomation auto, String command, int value) {
return auto.invoke(property(auto, command),
new Variant[]{new Variant(value)});
}
private static boolean setProperty(OleAutomation auto, String name,
String value) {
return auto.setProperty(property(auto, name), new Variant(value));
}
private static boolean setProperty(OleAutomation auto, String name,
int value) {
return auto.setProperty(property(auto, name), new Variant(value));
}
private static int property(OleAutomation auto, String name) {
return auto.getIDsOfNames(new String[]{name})[0];
}
}
Но он показывает следующую ошибку
Exception in thread "main" org.eclipse.swt.SWTException: Failed to create Ole Client. result = -2147221164
at org.eclipse.swt.ole.win32.OLE.error(OLE.java:302)
at org.eclipse.swt.ole.win32.OleClientSite.<init>(OleClientSite.java:242)
at tutorialjavamail.SendMail.execute(SendMail.java:44)
at tutorialjavamail.SendMail.main(SendMail.java:33)
Java Result: 1
Я новичок в обработке электронной почты на java, но я уже искал JavaMail, но, видимо, он не очень хорошо работает с серверами Microsoft Exchange.
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
, я думаю, моя проблема в том, что я не могу найти этот progID, и я где-то читал, что он запускает процесс на стороне сервера, а не как клиент Outlook (где я буду запускать код), Я просто не могу найти progID для Outlook 2007, даже в regedit - person Ces   schedule 15.04.2015