等待邮件不是 sent/closed 与 jacob

Wait while Mail is not sent/closed with jacob

我的应用程序使用 jacob 发送电子邮件。 现在我只想在某些情况下打开邮件并等待用户按下发送(或者他关闭邮件)

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

我已经用 while(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.

您需要处理 MailItem class 的 Send 事件,该事件在用户选择某个项目的“发送”操作时触发。

您还可能会发现应用程序 class 的 ItemSend 事件会在每次发送 Microsoft Outlook 项目时触发,或者由用户通过检查器(在检查器关闭之前,但在用户单击“发送”按钮之后)或在程序中使用 Outlook 项目(如 MailItem)的发送方法时。请注意,如果事件过程将 Cancel 参数设置为 true,则发送操作未完成并且检查器保持打开状态。