프로토콜“mapi : //”를 사용하여 Java의 Outlook에서 메일을 엽니 다.

StackOverflow https://stackoverflow.com/questions/2400223

  •  18-09-2019
  •  | 
  •  

문제

Windows 데스크탑 검색을 사용하여 Java 응용 프로그램을 개발하여 URL과 같은 컴퓨터의 파일에 대한 정보를 검색 할 수 있습니다.System.ITEMURL). 그러한 URL의 예는 다음과 같습니다

file://c:/users/ausername/documents/aninterestingfile.txt

"정상"파일의 경우. 이 필드는 또한 Outlook 또는 Thunderbird에서 색인 된 우편 품목의 URL을 제공합니다. Thunderbird의 항목 (Vista 및 Seven을 사용 하여만 사용할 수 있음)은 파일 (.WDSEML)입니다. 그러나 Outlook의 항목 URL은 "mapi : //"like로 시작합니다.

mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/toto@mycompany.com($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가

내가 가지고있는 문제는이 URL을 사용하여 Outlook에서 Java에서 실제 항목을 여는 것입니다. Windows의 실행 대화 상자에서 복사/붙여 넣으면 작동합니다. 또한 "시작"과 명령 줄에서 복사/붙여 넣은 URL을 사용하는 경우에도 작동합니다.

URL은 UTF-16에서 인코딩 된 것 같습니다. 그러한 코드를 쓸 수 있기를 원합니다.

String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/toto@mycompany.com($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";

Runtime.getRuntime().exec("cmd.exe /C start " + url);

나는 작동하지 않고 다음과 같은 다른 솔루션을 시도했습니다.

String start = "start";
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/toto@mycompany.com($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";

FileOutputStream fos = new FileOutputStream(new File("test.bat");
fos.write(start.getBytes("UTF16");
fos.write(url.getBytes("UTF16"));
fos.close();

Runtime.getRuntime().exec("cmd.exe /C test.bat");

아무런 성공도없이. 위의 솔루션을 사용하여 "test.bat"파일에는 올바른 URL과 "start"명령이 포함되어 있지만 "test.bat"의 실행은 잘 알려진 오류 메시지가 나타납니다.

'■' is not recognized as an internal or external command, operable program or batch file.

Java에서 "Mapi : //"항목을 열 수있는 아이디어가 있습니까?

도움이 되었습니까?

해결책

글쎄, 내 질문은 조금 까다로웠다. 그러나 나는 마침내 답을 찾아서 여기서 공유 할 것입니다.

내가 의심되는 것은 사실입니다. Windows는 UTF-16 (Little Endian) URL을 사용합니다. 이미지, 텍스트 등과 같은 파일의 경로 만 사용할 때 UTF-8에서 작동하지 않지만 Outlook 항목에 액세스하려면 UTF-16LE를 사용해야합니다. C#로 코딩한다면 아무런 문제가 없었을 것입니다. 그러나 Java에서는 더 독창적이어야합니다.

Windows 데스크탑 검색에서 다음을 검색합니다.

mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/toto@mycompany.com($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가

그리고 내가 한 일은 임시 VB 스크립트를 만들고 다음과 같이 실행하는 것입니다.

/**
 * Opens a set of items using the given set of paths.
 */
public static void openItems(List<String> urls) {
  try {

    // Create VB script
    String script =
      "Sub Run(ByVal sFile)\n" +
      "Dim shell\n" +
      "Set shell = CreateObject(\"WScript.Shell\")\n" +
      "shell.Run Chr(34) & sFile & Chr(34), 1, False\n" +
      "Set shell = Nothing\n" +
      "End Sub\n";

    File file = new File("openitems.vbs");

    // Format all urls before writing and add a line for each given url
    String urlsString = "";
    for (String url : urls) {
      if (url.startsWith("file:")) {
        url = url.substring(5);
      }
      urlsString += "Run \"" + url + "\"\n";
    }

    // Write UTF-16LE bytes in openitems.vbs
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(script.getBytes("UTF-16LE"));
    fos.write(urlsString.getBytes("UTF-16LE"));
    fos.close();

    // Run vbs file
    Runtime.getRuntime().exec("cmd.exe /C openitems.vbs");

  } catch(Exception e){}
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top