从所选Outlook电子邮件窗口中提取附件

时间:2014-11-12 05:03:59

标签: outlook outlook-addin

我写了下面的插件代码来保存选定的Outlook电子邮件中的附件。

 MailItem mailItem = null;
            Attachments mtAttachments = null;

            Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

            if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
            {
                object item = explorer.Selection[1];
                if (item is MailItem)
                {
                    mailItem = item as MailItem;
                    subject = mailItem.Subject;
                    body = mailItem.HTMLBody;
                    mtAttachments = mailItem.Attachments;

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

但问题是,它也是从签名中保存图像,这是完全错误的。

我只想保存电子邮件的附件。

任何人都可以帮助我。?

1 个答案:

答案 0 :(得分:0)

引用Getting Error Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

我已经更新了我的代码并且工作正常。

现在它只会下载附加到电子邮件的附件。

MailItem mailItem = null;
            Attachments mtAttachments = null;

            Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

            if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
            {
                object item = explorer.Selection[1];
                if (item is MailItem)
                {
                    mailItem = item as MailItem;
                    subject = mailItem.Subject;
                    body = mailItem.HTMLBody;
                    mtAttachments = mailItem.Attachments;

                    if (mailItem.Attachments.Count > 0)
                    {
                        for (int j = 1; j <= mailItem
                           .Attachments.Count; j++)
                        {
                            if (mailItem.Attachments[j].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7FFE000B") == false)
                            {
                                mailItem.Attachments[j].SaveAsFile
                                    (@"C:\TestFileSave\" +
                                    mailItem.Attachments[j].FileName);
                            }
                        }
                    }
                }
            }