只保存一个Outlook的MailItem的REAL附件 [英] Saving only the REAL attachments of an Outlook MailItem

查看:136
本文介绍了只保存一个Outlook的MailItem的REAL附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个Outlook外接程序,节省MailItems和附件在我的MSSQL数据库。

I'm currently developing an Outlook Addin which saves MailItems and Attachments in my MSSQL Database.

我在那里我保存的MailItem所有的方法它的附件。但是,如果我保存所有附件中的MailItem嵌入式图像也被保存。

I got a method where I save the MailItem with all it's attachments. But if I save all attachments the embedded images in the MailItem are also saved.

有谁知道如何保存所有的真正的附件?我的意思是像下面的图片附件:

Does anyone know how to save all real attachments?? I mean like the attachments in the picture below:

而不是embbeded的图像,在邮件正文。

and not the embbeded images that are in the mail body.

下面是代码,我通过的MailItem的所有附件使用循环,然后将其保存:

Here is the code that I use to loop through all attachments of a MailItem and then save it:

foreach (Outlook.Attachment att in mailItem.Attachments)
{
      try
      {
          att.SaveAsFile(Path.GetTempPath() + att.FileName);

          var fi = new FileInfo(Path.GetTempPath() + att.FileName);

          //Saving attachment to DB
          var attachment = Attachment.NieuwAttachment(att.FileName, SelectedMap.DossierNr.ToString( CultureInfo.InvariantCulture), -1, Convert.ToInt32(SelectedMap.Tag), fi);
          if (!Attachment.InlezenAttachment(attachment)) continue;

          OutlookCategories.AddAttachmentCategory(mailItem);
      }
      catch (Exception ex)
      {
          var dmsEx = new DmsException("Er is een fout opgetreden bij het opslaan van een bijlage.", ex.Message, ex);
          ExceptionLogger.LogError(dmsEx);
      }
 }



谢谢!

Thanks!

----------- ------------编辑

----------- EDIT ------------

我也贴了这个问题在微软的TechNet和我刚刚收到答案的问题(见下面的链接)

I also posted this question on the Microsoft TechNet and I just received an answer to the question (See link below)

的Outlook 2007和放大器; 2010:保存所有附件,除了嵌入式附件C#

----------- ---------编辑---

----------- EDIT ------------

我的问题是依然不动,我从微软得到的帮助是无用的。所以请我真的需要这个是固定的!

My problem is still not fixed, the help I got from Microsoft is useless.. So Please I really need this to be fixed!

推荐答案

使用此代码回答这里

if (mailItem.Attachments.Count > 0)
        {
            // get attachments
            foreach (Attachment attachment in mailItem.Attachments)
            {
                var flags = attachment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37140003");

                //To ignore embedded attachments -
                if (flags != 4)
                {
                    // As per present understanding - If rtF mail attachment comes here - and the embeded image is treated as attachment then Type value is 6 and ignore it
                    if ((int)attachment.Type != 6)
                    {

                        MailAttachment mailAttachment = new MailAttachment { Name = attachment.FileName };
                        mail.Attachments.Add(mailAttachment);
                    }

                }

            }
        }

这篇关于只保存一个Outlook的MailItem的REAL附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆