我使用OpenPop从电子邮件中提取附件,并将它们存储在本地驱动器上。
我看到的错误是
在System.RuntimeMethodHandle.InvokeMethod(Object目标、System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj的Object[]参数、签名sig、布尔构造函数、System.Reflection.RuntimeMethodInfo.Invoke(Object obj、bindingFlags invokeAttr、binder绑定器、Object[]参数、CultureInfo区域性的System.RuntimeType.InvokeMember(String name、BindingFlags BindingFlags、binder粘合剂、对象目标、Object[] providedArgs、ParameterModifier[]修饰符、CultureInfo区域性)处的Object[]参数、Object[]参数)Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()公司的String[] namedParams)
我不太确定如何调试这个问题。
我使用的代码如下..。
#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();
}发布于 2016-11-17 21:12:04
只要把这个放在你的文件的顶部:
using System.Collections.Generic;https://stackoverflow.com/questions/40665023
复制相似问题