Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我正在使用Koolwired.Imap通过Imap检索附件。_C#_Imap - Fatal编程技术网

C# 我正在使用Koolwired.Imap通过Imap检索附件。

C# 我正在使用Koolwired.Imap通过Imap检索附件。,c#,imap,C#,Imap,我正在使用Koolwired.Imap检索附件。下面是我编写的代码 使用K=Koolwired.Imap public void GetAttachmentsTest(string thread, string selectFolder, string fileName) { K.ImapConnect connect = new K.ImapConnect(Global.host); K.ImapCommand command = new K

我正在使用Koolwired.Imap检索附件。下面是我编写的代码

使用K=Koolwired.Imap

    public void GetAttachmentsTest(string thread, string selectFolder, string fileName)
    {

        K.ImapConnect connect = new K.ImapConnect(Global.host);

        K.ImapCommand command = new K.ImapCommand(connect);

        K.ImapAuthenticate auth = new K.ImapAuthenticate(connect, Global.username, Global.password);
        connect.Open();
        auth.Login();

        K.ImapMailbox mailBox = command.Select(Global.inbox);
        mailBox = command.Fetch(mailBox);

        K.ImapMailboxMessage mbstructure = new K.ImapMailboxMessage();

        while (true)
        {
            try
            {

                    int mailCount = mailBox.Messages.Count;

                    if (mailCount == 0)
                    {
                        Console.WriteLine("no more emails");
                        break;
                    }

                    for (int i = 0; i < mailCount; ++i)
                    {
                        mbstructure = mailBox.Messages[mailCount - 1];
                        mbstructure = command.FetchBodyStructure(mbstructure);

                        for (int j = 0; j < mbstructure.BodyParts.Count; ++j)
                        {
                            if (mbstructure.BodyParts[j].Attachment)
                            {
                                //Attachment
                                command.FetchBodyPart(mbstructure, mbstructure.BodyParts.IndexOf(mbstructure.BodyParts[j]));

                                //Write Binary File
                                string tempPath = Path.GetTempPath();
                                FileStream fs = new FileStream(tempPath + mbstructure.BodyParts[j].FileName, FileMode.Create);
                                int length = Convert.ToInt32(mbstructure.BodyParts[j].DataBinary.Length);
                                fs.Write(mbstructure.BodyParts[j].DataBinary, 0,length);
                                fs.Flush();
                                fs.Close();

                            }
                        }

                    }



            }
            catch (Exception ex)
            {
                Console.WriteLine("T1 " + ex.Message);
                Console.WriteLine("T1 " + ex.StackTrace);
                if (ex.InnerException != null)
                    Console.WriteLine("T1 " + ex.InnerException.Message);
            }
        }

    }
public void GetAttachmentsTest(字符串线程、字符串选择文件夹、字符串文件名)
{
K.ImapConnect connect=新的K.ImapConnect(Global.host);
K.ImapCommand命令=新的K.ImapCommand(连接);
K.ImapAuthenticate auth=新的K.ImapAuthenticate(connect,Global.username,Global.password);
connect.Open();
auth.Login();
K.ImapMailbox mailBox=command.Select(Global.inbox);
mailBox=command.Fetch(邮箱);
K.ImapMailboxMessage mbstructure=新的K.ImapMailboxMessage();
while(true)
{
尝试
{
int mailCount=mailBox.Messages.Count;
如果(邮件数==0)
{
Console.WriteLine(“不再发送电子邮件”);
打破
}
对于(int i=0;i
我在声明中遇到错误:

int length=Convert.ToInt32(mbstructure.BodyParts[j].DataBinary.length)

Write(mbstructure.BodyParts[j].数据库,0,长度)

错误是:

输入不是有效的Base-64字符串,因为它包含非Base-64字符、两个以上的填充字符或填充字符中的非法字符

当只有1个附件时,上述代码在显示的行中出现故障

如果有多个附件:

然后代码在第二行出现故障

mbstructure=command.FetchBodyStructure(mbstructure)

错误是:

无效格式无法分析正文部分标题

我很快就能完成这项任务了。谁能帮我一下吗

我也想知道如何删除电子邮件,一旦我检索他们


谢谢。

我也遇到了同样的问题 如果有人关心的话,我从codeplex下载了库的最新源代码,解决了这个问题。 一旦编译,它就可以正常工作,不会发生任何更改。看来他们已经修好了

同样,要删除电子邮件,只需将其标记为删除: command.SetDeleted(n,true);//->其中n是消息编号

如果是IMAP连接,实际上您必须删除已删除的邮件才能完成删除

command.Expunge()

希望它能帮助别人