感謝您的答案,但找到了一個很好的方式來做到這一點,我分享代碼給任何想做同樣事情或類似的人:
Shell shell = new Shell(getDisplay());
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", "");
/*
* Empty but could also be
* predefined
*/
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", filterComboBox.getSelectedItem().toString());
setProperty(mail, "HtmlBody", w.toString());
invoke(mail, "Display" /* or "Send" */);
和:
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];
}
你真的需要的Outlook模板? –
我只需要在郵件正文中預定義「東西」。它不一定是.oft模板。 – Foxticity