0

我需要将消息附件存储到本地硬盘驱动器中。是否有任何解决方法可以实现这一点?我正在使用 S22.Imap dll

using (ImapClient Client = new ImapClient("imap.gmail.com", 993,
            "xxxxxx@xxxxx.com", "xxxxxxxxxx", S22.Imap.AuthMethod.Login, true))
            {
                uint[] uids = Client.Search(
                    SearchCondition.From("test.account.rac@gmail.com").And(
                    SearchCondition.SentSince(new DateTime(2013, 5, 8))).And(
                    SearchCondition.SentBefore(new DateTime(2013, 5, 9)))
                );

                MailMessage[] messages = Client.GetMessages(uids,
                    (Bodypart part) =>
                    {
                        // We're only interested in attachments
                        if (part.Disposition.Type == ContentDispositionType.Attachment)
                        {
                            Int64 TwoMegabytes = (1024 * 1024 * 2);
                            if (part.Size > TwoMegabytes)
                            {
                                // Don't download this attachment
                                return false;
                            }
                        }

                        // fetch MIME part and include it in the returned MailMessage instance
                        return true;
                    }
                );
                string attachment_name;
                if (messages[0].Attachments.Count > 0)
                {




                }
            }

没有将这些附件保存到本地驱动器的内置方法。此外,这可以通过 S22.Mail.dll 库实现,但我找不到这个库。有人可以为我提供解决方案吗?这是 S22.Mail 源代码的链接https://github.com/smiley22/S22.Mail

4

1 回答 1

0

我试图在Pull #42中修复的库存在/存在一些问题(在编写此内容时,它尚未合并 - 您可能希望改为拉取该分支。)

然后迭代Message.Attachments而不是零件。 Net.Mail.Attachment.ContentStream会给你一个可以复制到文件的流。要检查大小,请使用ContentStream.Length.

如何保存流已深入介绍:如何将流保存到 C# 中的文件?

于 2013-08-25T23:49:10.313 回答