【问题标题】:Downloaded email attachment is not saved correctly using ImapX and C#使用 ImapX 和 C# 未正确保存下载的电子邮件附件
【发布时间】:2013-12-19 17:19:21
【问题描述】:

我正在用 C# 编写一个程序,以使用 ImapX(版本 2.0.0.13)访问来自 Gmail 的 UNREAD 电子邮件。我希望专门下载附件中的 powerpoint(.ppt 或 .pptx)文件。我已经完成了附件的下载工作。

但是,下载内容未正确保存在磁盘上。例如,如果附件大小为 3.5 MB,则仅保存 2.4 MB。

我在这里错过了一步吗?

这是我的代码:

using(ImapClient client = new ImapClient(host, port, true, true))
{
    if (client.Login(username, password))
    {
        FolderCollection folders = client.Folders;
        Message[] messages = client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Attachments, 100);

        for (int i = 0; i < messages.Length; i++)
        {
            if (messages[i].Attachments.Length > 0)
            {
                Attachment[] atts = messages[i].Attachments;
                for (int j = 0; j < atts.Length; j++)
                {
                    if (atts[j].FileName.Contains("ppt") || atts[j].FileName.Contains("pptx"))
                    {
                        atts[j].Download();
                        atts[j].Save(SAVE_LOCATION, atts[j].FileName);
                    }
                }
            }
        }
    }
}

【问题讨论】:

  • 你可以试试存储库中的最新代码吗?今天更新了,问题应该已经解决了,下载附件的性能也有了很大的提升。
  • 嗨 Pavel,我已经下载了最新的代码,现在就试试。非常感谢您对这个问题的帮助 :) 最好的问候,Himanshu

标签: c# email gmail email-attachments imapx


【解决方案1】:

我从ImapX site下载了更新的源代码后,问题就解决了。现在与上面的源代码完美结合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    相关资源
    最近更新 更多