2016-11-18 43 views
0

我正在開發的Java應用程序是其他人用來幫助我們日常活動的內部工具。當使用該工具(在調用下面的代碼的JButton印刷機上)時,我希望它打開一個新的Outlook EMail供用戶查看/編輯。爲什麼不能在64位系統上使用JAR在Eclipse中工作時打開32位Outlook ...?

起初我是在64位Eclipse中開發這個應用程序,並且無法讓SWT在我所有的研究中都打開Outlook。在運行64位和32位SWT之後,我有了一些想法來檢查Outlook,並確信公司使用的是32位。我加載了一個32位的日食,導入我的項目,SWT切換到32位,它的工作原理完全按照預期。

我注意到正在運行的進程是javaw.exe * 32,但64位Eclipse正在使用進程javaw.exe。我從32位Eclipse中導出JAR並給它一個鏡頭,並且沒有EMail出現。我檢查了JRE的安裝並看到了32位和64位,但我的公司有一個策略,只強制Java控制面板中的64位JRE。我與其他人一起工作,並得到安裝和啓用here。 JAR仍然無法打開電子郵件。我什至嘗試禁用64位,它仍然無法正常工作。

有什麼可以補救這種情況嗎?請讓我知道,如果我能更好地闡述或提供更多的信息!

package EDM_PKG; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.FillLayout; 
import org.eclipse.swt.ole.win32.OLE; 
import org.eclipse.swt.ole.win32.OleAutomation; 
import org.eclipse.swt.ole.win32.OleClientSite; 
import org.eclipse.swt.ole.win32.OleFrame; 
import org.eclipse.swt.ole.win32.Variant; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 

public class CreateEmail { 
private static Display display = new Display(); 
public static void sendEMail(String env) { 
    //String currUser = System.getProperty("user.name"); 
    String msg = getMessage(env); 
    String sub = getSubject(env); 
    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, "BodyFormat", 2 /* HTML */); 
    setProperty(mail, "Subject", sub); 
    setProperty(mail, "To", "[email protected]"); 
    setProperty(mail, "HtmlBody", msg); 

    invoke(mail, "Display" /* or "Send" */); 
    display = null; 
} 
private static String getMessage(String env) { 
    String msg = ""; 
    if (env.equalsIgnoreCase("quas")) { 
     msg = "<html><body>The <b>USER</b> excel has been migrated to <b>QUAS.</b><br><br> This email was generated by Excel Datatable Migrator.</body></html>"; 
    } else if (env.equalsIgnoreCase("prod")) { 
     msg = "<html><body>The <b>QUAS</b> excel has been migrated to <b>PROD.</b><br><br>This email was generated by Excel Datatable Migrator.</body></html>"; 
    } else { 
     msg = "Somthing happened with the automated message of EDM. Please contact the user with the eCode: "+System.getProperty("user.name")+".</body></html>"; 
    } 

    return msg; 
} 
private static String getSubject(String env) { 
    String sub = ""; 
    if (env.equalsIgnoreCase("quas")) { 
     sub = "EDM has been used to move USER to QUAS..."; 
    } else if (env.equalsIgnoreCase("prod")) { 
     sub = "EDM has been used to move QUAS to PROD..."; 
    } else { 
     sub = "Somthing didnt quite work right..."; 
    } 

    return sub; 
} 
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]; 
} 
} 
+0

首先,發佈您用於從Java打開Outlook的代碼。第二:你已經把它標記爲'SWT',但你正在談論一個'JButton',那它是哪一個? – Baz

+0

該按鈕按下sendmessage,謝謝你看看,請讓我知道,如果有任何其他信息,我可以給。 –

+0

我只是簡單地調用這個不會做? 'Program.launch(「mailto:[email protected]&subject=Subject&body=Message here」);' – Baz

回答

0

有沒有必要使用重量級和難以使用Ole類。 如果你想要的是發送電子郵件,只需撥打這個:

Program.launch("mailto:[email protected]&subject=Subject&body=Me‌​ssage here"); 

這將在所有的架構和操作系統上運行。

相關問題