2017-03-06 15 views
0

私は、一連のフォルダを実行するoutlook addinをディスクに保存し、ゴミ箱フォルダに移動します。MailItemに関する情報を取得できません

私が追加したコードは、電子メールの99%で動作しています。 tryキャッシュの束はデバッグのためのものなので、無視してください。

1日に数千本のメールを抽出し、1つのフォルダ内のメールを除いてすべて機能します。

アイテムがMailItemsであり、すべてがチェックアウトしているかどうかをチェックしますが、プロパティを取得しようとするとすぐにこのタイプのエラーが発生します。

そのようなインターフェイスサポート(HRESULTからの例外:0x80004002の (E_NOINTERFACE))

10時57分51秒AM: Microsoft.Office.Interop.Outlook._MailItem.get_ReceivedTime(AT)

私がアクセスしようとしているものに基づいてメソッドが変わります。

しばらくの間、解決策を探していたが、役に立たなかった。

助けてください。

while (unreadFolders.Count > 0 && count < COUNT) 
      { 
       Outlook.Folder currentFolder = unreadFolders.FirstOrDefault().Key; 
       string path = unreadFolders.FirstOrDefault().Value; 
       Debug.WriteLine("reading folder: " + currentFolder.Name); 
       unreadFolders.Remove(currentFolder); 

       Outlook.Folder parent = GetParent(currentFolder); 
       var t = parent?.FullFolderPath; 
       //replenish the list 
       foreach (Outlook.Folder f in currentFolder.Folders) unreadFolders.Add(f, path + "\\" + f.Name); 

       //create directory if it doesnt exist 
       Directory.CreateDirectory(path); 

       Outlook.Items items = currentFolder.Items; 
       foreach (var item in items) 
       { 
        if (item != null && item is Outlook.MailItem) 
        { 
         if (count++ > COUNT) break; 
         var mailItem = (Outlook.MailItem)item; 
         if (mailItem == null) continue; 
         var fullpath = path + "\\"; 
         try 
         { 
          fullpath += "[(R)" + mailItem.ReceivedTime.ToWeirdDateFormat() + "]"; 
         } 
         catch (Exception ex) 
         { 
          using (StreamWriter file = new StreamWriter(@"C:\\temp\logs.txt", true)) 
          { 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\tReceived Time Broken"); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.Message); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.StackTrace); 
          } 
         } 
         try 
         { 
          fullpath += "[(T)" + mailItem.To.MakeWindowsSafe() + "]"; 
         } 
         catch (Exception ex) 
         { 
          using (StreamWriter file = new StreamWriter(@"C:\\temp\logs.txt", true)) 
          { 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\tTo Broken"); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.Message); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.StackTrace); 
          } 
         } 
         try 
         { 
          fullpath += "[(F)" + mailItem.SenderName.MakeWindowsSafe() + "]"; 
         } 
         catch (Exception ex) 
         { 
          using (StreamWriter file = new StreamWriter(@"C:\\temp\logs.txt", true)) 
          { 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\tSender name Broken"); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.Message); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.StackTrace); 
          } 
         } 
         try 
         { 
          fullpath += "[+][(S)" + mailItem.Subject.MakeWindowsSafe() + "]"; 
         } 
         catch (Exception ex) 
         { 
          using (StreamWriter file = new StreamWriter(@"C:\\temp\logs.txt", true)) 
          { 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\tSubject Broken"); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.Message); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + ex.StackTrace); 
          } 
         } 
         fullpath += ".msg"; 
         //save message to directory 
         mailItem.SaveAs(fullpath, Outlook.OlSaveAsType.olMSG); 

         //move message to deleted 
         if (parent == null) 
         { 
          using (StreamWriter file = new StreamWriter(@"C:\\temp\logs.txt", true)) 
          { 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\tParent Null"); 
           file.WriteLine(DateTime.Now.ToLongTimeString() + ":\t\t" + currentFolder.FullFolderPath); 
          } 
         } 
         else 
         { 
          mailItem.Move(parent.Folders["Deleted Items"]); 
         } 
        } 
       } 
      } 

答えて

0

MailItem.Classプロパティの値を確認してください - それは、46(OlObjectClass.olReport)であってもよい(とMailItem.MessageClassはREPORT.IPM.Note.NDRだろう)。配信不能なレポートメッセージはReportItemオブジェクトですが、MailItemオブジェクトとみなすことができ、評価を渡すことができます。

また、アイテムを別のフォルダに移動してコレクションを変更している可能性があります(また、ループごとにOutlookオブジェクトで使用するのが悪いため)逆方向カウンタループを使用していることを確認してください。また、Outlookオブジェクトを保持する変数でMarshal.ReleaseCOMObjectを呼び出すことも、常に良い考えです。

+0

明日はこれをチェックするためにメールボックスにアクセスするだけですが、私がアクセスしたときに私はそのメッセージを通って行きました。彼らは私に普通のメッセージであるように見えました。 MailItem.Classプロパティ値はどのようにすべきですか? ループで使用するコードを変更して、今すぐReleaseComObjectを使用しますが、明日の確認のみ可能です。 – LeftOfHere

+0

43. thanks msdn docs。 – LeftOfHere

+0

foreachループの代わりにforループを使用すると助けになりました。 また、comオブジェクトを適切に解放する必要がありました。 [msdn質問](https://social.msdn.microsoft.com/Forums/vstudio/en-US/e460d068-f872-44cd-a032-8f74e92d68f8/failing-to-get-any-info-on-mailitem?フォーラム= outlookdev) – LeftOfHere

関連する問題