How to open outlook using javaScript on client machine?

末鹿安然 提交于 2019-12-12 02:10:43

问题


I Have java code which open outlook in server . but i want to opent outlook on client machine and fill Body with HTML content . is it possible using javaScript , VbScript or any other Technology .

          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" */);

    }

回答1:


HTML - Javascript: Simple mailto in html a tag, see below for the simple markup.

<a href="mailto:name@gmail.com">Click here to mail</a>

Once clicked, it will open Outlook. (Actually it will open the default mail client)

Java:

Sample code: open Outlook and add an attachment.

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

First Argument = path to Outlook.

Second Argument = Outlook attachment command.

Third Argument = Attachment path.



来源:https://stackoverflow.com/questions/31405586/how-to-open-outlook-using-javascript-on-client-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!