2

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

    }
Vikram Pareek
  • 21
  • 1
  • 2

1 Answers1

0

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.

RobSeg
  • 985
  • 4
  • 14
  • 37
  • but this code not working properly in Windows-8 . it open default microsoft account instead of outlook. – Vikram Pareek Jul 14 '15 at 12:27
  • yes, as I said, this opens the users default mail client. If your default mail client is a microsoft account, that's what it opens IF the users default mail client is outlouk, it opens outlook. Assuming you want to send a mail, the client is not relevant wether it's outlouk, mail, or something else – RobSeg Jul 14 '15 at 12:53
  • can we open outlook uisng java code on client machine ?? – Vikram Pareek Jul 15 '15 at 06:09