在组织者的日历中找不到会议

时间:2020-05-29 19:12:16

标签: java email calendar ical4j

我正在尝试使用ical4j 1.0.4和javax邮件1.5.0库发送Outlook会议邀请(2013年展望版)。

我关注了这篇文章How to send an iCal meeting request using Java Mail, and receive the response,并且能够发送Outlook会议邀请。

但是组织者没有收到日历邀请。
如果我通过电子邮件ID向我发送会议邀请,我会收到活动,但会显示“日历中找不到会议”。

所有与会者都可以接收活动,他们可以接受/拒绝活动,也可以在日历中查看条目。

有什么方法可以将会议添加到组织者的日历中?

1 个答案:

答案 0 :(得分:0)

如果要在管理器日历中创建会议,建议从基于Java的应用程序中自动执行Outlook。您可以考虑使用Ole自动化技术来自动执行Outlook,例如:

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 OutlookMail {
    public static void main(String[] args) {
        sendEMail();
    }

    public static void sendEMail() {
        Display display = new Display();
        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", "My test subject");
//      setProperty(mail, "From", "my@sender.org");
        setProperty(mail, "To", "<John Doe> my@recipient.org");
        setProperty(mail, "HtmlBody", "<html><body>This is an <b>HTML</b> test body.</body></html>");

//      if (null != attachmentPaths) {
//          for (String attachmentPath : attachmentPaths) {
//              File file = new File(attachmentPath);
//              if (file.exists()) {
//                  OleAutomation attachments = getProperty(mail, "Attachments");
//                  invoke(attachments, "Add", attachmentPath);
//              }
//          }
//      }

        invoke(mail, "Display" /* or "Send" */);

    }

    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];
    }
}

有关更多信息,请参见How to create an E-Mail in Outlook and make it visible for the User

您可以在以下文章中找到来自Outlook对象模型的属性和方法调用的顺序:

相关问题