2

サーバーで Outlook を開く Java コードがあります。しかし、クライアント マシンで Outlook を開き、Body に 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" */);

    }
4

1 に答える 1

0

HTML - Javascript : シンプルなmailtohtmlaタグ。シンプルなマークアップについては以下を参照してください。

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

クリックすると、Outlook が開きます。(実際にはデフォルトのメールクライアントが開きます)

ジャワ

サンプル コード: Outlook を開いて添付ファイルを追加します。

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

最初の引数 = Outlook へのパス。

2 番目の引数 = Outlook 添付コマンド。

3 番目の引数 = 添付ファイルのパス。

于 2015-07-14T12:20:32.597 に答える