【问题标题】:S22.Imap save message attachment to local hard diskS22.Imap 将邮件附件保存到本地硬盘
【发布时间】:2013-05-09 10:40:29
【问题描述】:

我需要将邮件附件存储到本地硬盘驱动器中。是否有任何解决方法可以实现此目的?我正在使用 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的链接。

【问题讨论】:

    标签: asp.net c#-4.0 imap


    【解决方案1】:

    我试图在Pull #42 中修复的库存在/存在一些问题(在编写本文时它尚未合并 - 您可能想要拉该分支。)

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

    如何保存流已在:How do I save a stream to a file in C#?

    【讨论】:

    • 嘿尼基兹。感谢您的回复。不幸的是,我无法对此进行测试,因为我没有从事该特定项目。不知何故,我使用了其他一些库来实现此功能。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    相关资源
    最近更新 更多