如何确定用户是否发送了从Java代码生成的MS Outlook消息?

问题描述:

在我的程序中,我创建Outlook.exe进程并发送带有预填充的包含的消息.发送消息或关闭消息窗口后,我需要知道用户是否发送了消息.

In my program I create Outlook.exe process and send message with pre-populated contain. After sending message or closing message window I need to know whether or not user sent message.

exitValue()的处理方法无济于事,因为两种情况下的exitValue均为0.

exitValue() method of process doesn't help because exitValue in both cases is 0.

ProcessBuilder processBuilder = new ProcessBuilder();
Process process = processBuilder.command("C:\\Program Files(x86)\\Microsoft Office\\Office15\\OUTLOOK.exe", "/a").start();
if (process.exitValue() == 0) {
    Session session = sessionExtracting();
    session.beginTransaction();
    SQLQuery query = session.createSQLQuery("UPDATE mailorder set mailordstatus = 2");
    query.executeUpdate();
    session.close();
}

首先,Outlook是一个单例-如果Outlook.exe已经在运行,则启动第二个实例将把控制权简单地转移到第一个实例.其次,您要对Outlook.exe文件的位置进行硬编码.

Firstly, Outlook is a singleton - if outlook.exe is already running, launching the second instance will simply transfer control to the first instance. Secondly, you are hardcoding the outlook.exe file location.

使用Outlook对象模型(使用COM桥)-创建Outlook.Application COM对象的实例,使用Application.CreateItem(0)创建新消息,填充消息属性(主题,正文,收件人等).调用MailItem.Send或使用MailItem.Display显示消息并捕获MailItem.Send事件.

Use the Outlook Object Model (use a COM bridge) - create an instance of the Outlook.Application COM object, create new message using Application.CreateItem(0), populate the message properties (subject, Body, Recipients, etc,.) and either call MailItem.Send or display the message using MailItem.Display and trap the MailItem.Send event.