2017-04-21 14 views
10

Outlookで基本的なカスタムタスクペインを作成しました。電子メールをキャプチャする方法

電子メールをドラッグしてタスクペインにドロップしたいとします。それをドロップすると、電子メールを私が推測するオブジェクトとして捕捉できるようになります。たとえば、共有ポイントの場所に保存する場合と同じように、私はそれを使ってメールを送信できます。

これは可能ですか?もしそうなら、どんなポインタですか?

私はVS2013 C#.NET 4.0を使用しています。アドインはOutlook 2010/2013用です。

+0

あなたは "それで何かを行う" とはどういう意味ですか? raw .msgファイルとしてメールメッセージにアクセスするだけで十分ですか? (ファイル名と生のバイトとしての内容) –

答えて

5

前提条件とセットアップ

  • のWindows 10のPro
  • のVisual Studio 2013究極のOffice開発
  • Outlookとは2013年電子メールアカウント

プロジェクト

Visual Studioで
  • 新規プロジェクトを選択 - >ビジュアルC# - >オフィス/ SharePointの - >オフィスアドイン - >展望2013アドイン
  • プロジェクトを右クリック - > [追加] - > [ユーザーコントロール
  • 開く "ThisAddIn.cs" と "ThisAddIn_Startup" メソッドに次のコードを追加します。

    var myCustomPane= this.CustomTaskPanes.Add(new UserControl1(), "My Pane"); 
    myCustomPane.Visible = true; 
    

Outlook 2013 Custom Pane

ドラッグアンドドロップメッセージ

  • ソリューションエクスプローラでUserControl1をダブルクリックします。デザイナーウィンドウが開きます。プロパティで
  • AllowDrop = Trueのを設定し、2つのイベントハンドラドラッグアンドドロップのDragEnterをフックアップ。

    private void UserControl1_DragEnter(object sender, DragEventArgs e) 
    { 
        // if you want to read the message data as a string use this: 
        if (e.Data.GetDataPresent(DataFormats.UnicodeText)) 
        { 
         e.Effect = DragDropEffects.Copy; 
        } 
        // if you want to read the whole .msg file use this: 
        if (e.Data.GetDataPresent("FileGroupDescriptorW") && 
         e.Data.GetDataPresent("FileContents")) 
        { 
         e.Effect = DragDropEffects.Copy; 
        } 
    } 
    
    private void UserControl1_DragDrop(object sender, DragEventArgs e) 
    { 
        // to read basic info about the mail use this: 
        var text = e.Data.GetData(DataFormats.UnicodeText).ToString(); 
        var message = text.Split(new string[] { "\r\n" }, StringSplitOptions.None)[1]; 
        var parts = message.Split('\t'); 
        var from = parts[0]; // Email From 
        var subject = parts[1]; // Email Subject 
        var time = parts[2]; // Email Time 
    
        // to get the .msg file contents use this: 
        // credits to "George Vovos", http://stackoverflow.com/a/43577490/1093508 
        var outlookFile = e.Data.GetData("FileGroupDescriptor", true) as MemoryStream; 
        if (outlookFile != null) 
        { 
         var dataObject = new iwantedue.Windows.Forms.OutlookDataObject(e.Data); 
    
         var filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); 
         var filestreams = (MemoryStream[])dataObject.GetData("FileContents"); 
    
         for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) 
         { 
          string filename = filenames[fileIndex]; 
          MemoryStream filestream = filestreams[fileIndex]; 
    
          // do whatever you want with filestream, e.g. save to a file: 
          string path = Path.GetTempPath() + filename; 
          using (var outputStream = File.Create(path)) 
          { 
           filestream.WriteTo(outputStream); 
          } 
         } 
        } 
    } 
    

あなたはCodeProjectから"iwantedue.Windows.Forms.OutlookDataObject"を得ることができるか、このGitHub gistを使用することができます。

デモ

Outlook 2013 Custom Pane Drag and drop email message

+1

クレジットはDavid Ewenに行くべきです:)私たちの答えは、基本的にコードプロジェクトに関する彼の作品です。私は何の問題もなくOPを実際に問題があるかどうかわからない前にそれを使用している... –

0

はあなたがここにOutlookEmailObjectクラスを取得することができ、この

 public static string[] GetDropedFiles(DragEventArgs e) 
     { 
      string[] files = null; 
      var outlookFile = e.Data.GetData("FileGroupDescriptor", true) as MemoryStream; 
      if (outlookFile != null) 
      { 
       OutlookEmailObject dataObject = new OutlookEmailObject(e.Data); 

       var filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); 
       var filestreams = (MemoryStream[])dataObject.GetData("FileContents"); 

       files = new string[filenames.Length]; 
       for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) 
       { 
        string filename = filenames[fileIndex]; 
        MemoryStream filestream = filestreams[fileIndex]; 

        string path = Path.GetTempPath(); 
        string fullFileName = path + filename; 

        FileStream outputStream = File.Create(fullFileName); 
        filestream.WriteTo(outputStream); 
        outputStream.Close(); 

        files[fileIndex] = fullFileName; 
       } 
      } 
      else 
       files = (string[])e.Data.GetData(DataFormats.FileDrop); 

      return files; 
     } 

のようなものを試してみてください(コードサンプルをダウンロードしてください) :
http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C

(作業が完了した後もちろん、あなたはすべての一時ファイルを削除する必要があります彼らは)

関連する問題