不要保存包含在附件中的嵌入图像(如签名图像) [英] Don't save embed image that contain into attachements (like signature image)

查看:30
本文介绍了不要保存包含在附件中的嵌入图像(如签名图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# 中处理 VSTO.当我点击按钮时,我将附件保存在一个文件夹中.我的问题是:当我有一封带有签名的图片的丰富电子邮件时,我的附件中有一个元素.但我不想保存那个图像.Outlook(应用程序)在附件区域隐藏此附件!那为什么不是我:-(

I work on a VSTO in c#. When I click on button I save attachment in a folder. My problem is : when I have a rich email with an image in the signature, I have a element in my attachment. But I don't want save that image. Outlook (application) hide this attachment in the area attachment ! So why not me :-(

我的代码很简单:

MailItem MailItemSelected =  this.OutlookItem;   
foreach (Attachment a in MailItemSelected.Attachments)
{
   a.SaveAsFile(path + a.FileName);
}

但我没有找到不保存签名图像的测试.

But I don't find a test for don't save the image of the signature.

推荐答案

我找到了我的解决方案的一部分.当您创建电子邮件时,嵌入的图像大小为 0.因此您可以将其排除在外.

I've find one part of my solution. When you create an email the size of image embed is to 0. So you can exclude this.

但是当我阅读电子邮件时这是不对的.

But it is not right when I read a email.

MailItem MailItemSelected =  this.OutlookItem;   
foreach (Attachment a in MailItemSelected.Attachments)
{                                    
   if(a.Size != 0)
      a.SaveAsFile(path + a.FileName);
}

当我阅读电子邮件时,我找到了一个解决方案,但它不是很好.所以我写了它,但如果有人认为有更好的,我喜欢它.在我的示例中,我尝试使用 PropertyAccessor 获取 Flag 属性,如果它是嵌入图像,则没关系,否则我会引发异常.

When I read email I found a solution, but it is not very nice. So I write it, but if anybody think have better, I like it. In my example I try to get the Flag property with the PropertyAccessor, if it's a embed image, it's ok else I've an exception that be raise.

MailItem MailItemSelected =  this.OutlookItem;   
foreach (Attachment a in MailItemSelected.Attachments)
{
   bool addAttachment = false;
   try
   {
      string schemaPR_ATTACH_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x37140003"; 
      a.PropertyAccessor.GetProperty(schemaPR_ATTACH_FLAGS);
   }
   catch
   {
      addAttachment = true;
   }

   if (addAttachment && (a.Size != 0))
      a.SaveAsFile(path + a.FileName);
}

这篇关于不要保存包含在附件中的嵌入图像(如签名图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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