C#下载电子邮件附件 - 而不是单个文件网页

时间:2014-11-21 15:59:58

标签: c# email outlook attachment

我有以下代码来下载.xls格式的电子邮件附件。

Application app = new Application();
        NameSpace ns = app.GetNamespace("MAPI");

        string recipientName = "aaa.bbb@ccccccc.xx";

        Recipient recip = ns.CreateRecipient(recipientName);
        recip.Resolve();

        if (recip.Resolved)
        {
            MAPIFolder inboxFolder = ns.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderInbox);
            Items items = (Items)inboxFolder.Items;
            items = items.Restrict("[Unread] = true");

            foreach (MailItem eMail in items)
            {
                string Subject = eMail.Subject;

                if (Subject == "xxxxxxxxx")
                {

                    if (eMail.Attachments.Count > 0)
                    {
                        for (int i = 1; i <= eMail.Attachments.Count; i++)
                        {
                            eMail.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + eMail.Attachments[i].FileName);
                        }
                    }
                }
            }

        }

一切正常,但是当我尝试打开xls文件时,它会显示该文件的文件格式与文件扩展名指定的文件格式不同。

我看到附件被下载为单个文件网页,是否有任何技巧以真正的.xls格式保存?

0 个答案:

没有答案