首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenPop -运行时错误

OpenPop -运行时错误
EN

Stack Overflow用户
提问于 2016-11-17 21:06:05
回答 1查看 144关注 0票数 0

我使用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)

我不太确定如何调试这个问题。

我使用的代码如下..。

代码语言:javascript
复制
#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();
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-17 21:12:04

只要把这个放在你的文件的顶部:

代码语言:javascript
复制
using System.Collections.Generic;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40665023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档