2016-11-17 4 views
0

私は電子メールから添付ファイルを抽出し、それらをローカルドライブに保存するためにOpenPopを使用しています。OpenPop - ランタイムエラー

私は見ていますエラーがSystem.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(オブジェクトobj、で ([]引数、署名SIG、ブールコンストラクタオブジェクト、オブジェクトのターゲット)System.RuntimeMethodHandle.InvokeMethodで

ですSystem.RuntimeType.InvokeMember(String name、BindingFlags bindingFlags)で をSystem.Reflection.RuntimeMethodInfo.Invoke(Object obj、BindingFlags invokeAttr、バインダーバインダー、Object []パラメーター、CultureInfoカルチャ)で に設定します。 、バインダーバインダー、オブジェクトターゲット、ObjectArgs、ParameterModifier []修飾子、CultureInfoカルチャ、String [] namedParams)Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScriptで()

私は、この問題をデバッグする方法が本当にわかりません。

次のように私が使用していたコードがある...

#region Namespaces 
using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Runtime; 
using System.IO; 
using OpenPop.Mime; 
using OpenPop.Mime.Header; 
using OpenPop.Pop3; 
using OpenPop.Pop3.Exceptions; 
using OpenPop.Common.Logging; 
using System.Linq; 
#endregion 
//....... 
     var client = new Pop3Client(); 
     try 
     { 
      client.Connect("outlook.office365.com", port, true); //UseSSL true or false 
      client.Authenticate("user", "password"); 

      var messageCount = client.GetMessageCount(); 
      var Messages = new System.Collections.Generic.List<Message>(messageCount); 

      for (int i = 0; i < messageCount; i++) 
      { 
       Messages.Add(client.GetMessage(i + 1)); 
      } 

      foreach (Message msg in Messages) 
      { 
       foreach (var attachment in msg.FindAllAttachments()) 
       { 
        string filePath = Path.Combine(@"D:\validations\Attachments", attachment.FileName); 
        if (Path.GetExtension(filePath) == ".xlsx")//Path.GetExtension(filePath) == ".xlsx" attachment.FileName.Equals("blabla.pdf") 
        { 
         FileStream Stream = new FileStream(filePath, FileMode.Create); 
         BinaryWriter BinaryStream = new BinaryWriter(Stream); 
         BinaryStream.Write(attachment.Body); 
         BinaryStream.Close(); 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine("", ex.Message); 
     } 
     finally 
     { 

      if (client.Connected) 
       client.Dispose(); 
     } 

答えて

0

ちょうどあなたのファイルの先頭にこれを配置します。

using System.Collections.Generic;