【问题标题】:How to open outlook using javaScript on client machine?如何在客户端机器上使用 JavaScript 打开 Outlook?
【发布时间】:2015-08-25 03:39:12
【问题描述】:

我有在服务器中打开 Outlook 的 java 代码。但我想在客户端机器上打开 Outlook 并用 HTML 内容填充正文。是否可以使用 javaScript、VbScript 或任何其他技术。

          public static void main(String[] args) {
//  System.setProperty("java.library.path", "/path/to/library");

    Display display = Display.getCurrent();
    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, "To", "testTo@gmail.com"); /*
                           * Empty but could also be
                           * predefined
                           */
    setProperty(mail, "Bcc", "testBcc@gmail.com"); /*
                           * Empty but could also be
                           * predefined
                           */
    setProperty(mail, "Cc", "testCc@gmail.com"); /*
     * Empty but could also be
     * predefined
     */
    setProperty(mail, "BodyFormat", 2 /* HTML */);
    setProperty(mail, "Subject", "Top News for you");
    setProperty(mail, "HtmlBody",
        "<html>Hello<p>, please find some infos here.</html>");
    File file = new File("d:/vicky.txt");
    if (file.exists()) {
      OleAutomation attachments = getProperty(mail, "Attachments");
      invoke(attachments, "Add", "d:/vicky.txt");
    } else {
      MessageDialog
          .openInformation(shell, "Info",
              "Attachment File c:/temp/test.txt not found; will send email with attachment");
    }
    invoke(mail, "Display" /* or "Send" */);

    }

【问题讨论】:

    标签: javascript vbscript outlook.application


    【解决方案1】:

    HTML - Javascript:简单的mailto in html a 标记,请参见下面的简单标记。

    &lt;a href="mailto:name@gmail.com"&gt;Click here to mail&lt;/a&gt;

    单击后,它将打开 Outlook。 (其实它会打开默认的邮件客户端)

    Java

    示例代码:打开 Outlook 并添加附件。

    new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start();
    

    第一个参数 = Outlook 的路径。

    第二个参数 = Outlook 附件命令。

    第三个参数 = 附件路径。

    【讨论】:

    • 但此代码在 Windows-8 中无法正常工作。它打开默认的微软帐户而不是 Outlook。
    • 是的,正如我所说,这会打开用户的默认邮件客户端。如果您的默认邮件客户端是 microsoft 帐户,它会打开它如果用户的默认邮件客户端是 outlouk,它会打开 Outlook。假设您要发送邮件,无论是 outlouk、mail 还是其他东西,客户端都不相关
    • 我们可以在客户端机器上打开outlook uisng java代码吗??
    猜你喜欢
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    相关资源
    最近更新 更多