2015-07-20 23 views
0

我的應用程序發送電子郵件與雅各。 現在我只想在某些情況下,打開郵件並等待用戶按發送(或他關閉了郵件)等待郵件不發送/關閉與雅各

ActiveXComponent axcOutlook = new ActiveXComponent("Outlook.Application"); 
Dispatch mail = Dispatch.invoke(axcOutlook.getObject(), "CreateItem", Dispatch.Get, new Object[] { "0" }, new int[0]).toDispatch(); 
... 
Dispatch.put(mail, "Subject", subject); 
Dispatch.put(mail, "Body", sbBody.toString()); 
Dispatch.put(mail, "ReadReceiptRequested", "false"); 
Dispatch.call(mail, "Display"); 
//And here I want to wait till the Mail is sent/closed 

我已經有一段時間(true)循環

while (true) { 
    if (Dispatch.get(mail, "Sent").getBoolean()) { 
     return; 
    } 
} 
試了一下

但是這個計算策略我得到一個異常(我已經發送後的郵件):

com.jacob.com.ComFailException: Invoke of: Sent

Source: Microsoft Outlook

Description: the element was moved or deleted.

回答

1

您需要處理Send事件當用戶選擇一個項目發送動作被解僱的MailItem類的。

此外,您可能會發現應用程序類的ItemSend事件,每當用戶通過Inspector(在檢查器關閉之前,但在用戶單擊發送按鈕之後)發送Microsoft Outlook項目時觸發,或者當某個Outlook項目的Send方法(如MailItem)在程序中使用時。請注意,如果事件過程將Cancel參數設置爲true,則發送操作未完成且檢查器處於打開狀態。

+0

不錯。 'Send'event正在工作。但我無法驗證郵件是否已關閉。我確實收到了「關閉」事件,但它出現在「你想保存......」之前。如果您在Outlook中選擇取消,則即使Mail仍處於打開狀態,該事件也會被解除。你有什麼想法如何解決這個問題? – griFlo

+0

好的。我沒有找到解決我的近距離問題的答案。所以在我爲此浪費更多時間之前,如果關閉事件被觸發,我只需關閉該項目而不手動。 – griFlo